Intermediate YAML

CI/CD for Machine Learning

Ravi Bhadauria

Machine Learning Engineer

Multiline strings: Block scalar format

  • Represent multiline strings or blocks of text
    • Code snippets (shell commands)
    • Paragraphs (logs)
    • Configuration files

A hierarchical plot of YAML Block string, with the root node "Block String" highlighted.

CI/CD for Machine Learning

Style indicators - literal

  • Literal style (|): preserves line break and indentation
  • Useful for writing shell commands
commands: |
  echo "Running python script..."
  python3 script.py

A hierarchical plot of YAML Block string, with the leaf node "Literal Style" highlighted.

CI/CD for Machine Learning

Literal style example

YAML example of a text written in literal multiline style. The text is preceded by the "|" symbol.

Output of the text written in YAML literal multiline style.

1 https://yaml-multiline.info/
CI/CD for Machine Learning

Style indicators - fold

  • Fold style (>): removes line breaks
  • Useful for writing wrapped messages like paragraphs
message: >
  Successfully executed the code!
  All processes completed 
  without any errors.
  The results have been saved 
  in the designated
  output directory.

A hierarchical plot of YAML Block string, with the leaf node "Fold Style" highlighted.

CI/CD for Machine Learning

Fold style example

YAML example of a text written in fold multiline style. The text is preceded by the ">" symbol.

Output of the text written in YAML fold multiline style.

1 https://yaml-multiline.info/
CI/CD for Machine Learning

Chomping indicators

  • Control the behavior of newlines at the end of the string
  • Added after the style indicators
  • clip: default mode, single newline at the end
    • No additional symbol needed for representation

A hierarchical plot of YAML Block string, with the leaf node "Clip Chomping indicator" highlighted.

CI/CD for Machine Learning

Chomping indicators - strip

  • strip (-): removes all newlines at the end

A hierarchical plot of YAML Block string, with the leaf node "Strip Chomping indicator" highlighted.

CI/CD for Machine Learning

Strip chomping example

YAML example of a text written in literal multiline style with strip chomping. The text is preceded by the "|-" symbol.

Output of the text written in YAML literal multiline style with strip chomping. The latter removes all newlines at the end.

1 https://yaml-multiline.info/
CI/CD for Machine Learning

Chomping indicators - keep

  • keep (+): retains all newlines at the end

A hierarchical plot of YAML Block string, with the leaf node "Keep Chomping indicator" highlighted.

CI/CD for Machine Learning

Keep chomping example

YAML example of a text written in literal multiline style with keep chomping. The text is preceded by the "|+" symbol.

Output of the text written in YAML literal multiline style with keep chomping. The latter doesn't remove any newlines at the end.

1 https://yaml-multiline.info/
CI/CD for Machine Learning

Dynamic value injection

  • Expressions allow parsers to dynamically substitute values
  • Usage:
    • Environment variables
    • References to other parts of YAML
  • Typically represented as ${{ ... }}
database:
  host: ${{ config.database.host }}
  port: ${{ config.database.port }}
  username: ${{ config.database.username }}
  password: ${{ config.database.password }}
CI/CD for Machine Learning

Multi-document YAML

  • Multiple separate YAML documents within a single file
  • Each document contains valid YAML content
  • Easy to organize by related documents
  • Separate documents by three dashes –––
___
- name: John
  age: 30
___
- name: Jane
  age: 28
___
- name: Bob
  age: 35
  occupation: Developer
CI/CD for Machine Learning

Summary

Name YAML Symbol
Literal Style Indicator |
Fold Style Indicator >
Strip Chomping Indicator
Keep Chomping Indicator +
Expressions ${{ ... }}
Multi-document YAML –––
CI/CD for Machine Learning

Let's practice!

CI/CD for Machine Learning

Preparing Video For Download...