AI Hints
CI/CD with GitHub Actions · Lesson 14 of 138

Multi-line Strings

Pipe and fold.

⏱ 2 min read▶ Video at 15:43🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Pipeline steps often need several commands, or one long command. YAML has two special symbols for text that spans many lines. The pipe keeps the line breaks, and the greater than sign folds them into spaces.

Multi-line Strings
From the video: Multi-line Strings
  • Steps need several commands
  • Text over many lines
  • The pipe and the arrow

Pipe and folded

After the pipe, every line is kept exactly as it is, line breaks and all. That's perfect for running several commands in one step. After the greater than sign, the lines are folded together, joined with spaces, which suits one long command or message.

text.ymlyaml
script: |
  echo "Installing"
  pip install -r requirements.txt
  echo "Done"
message: >
  This is one long sentence
  written over three lines
  in the file.

What each one becomes

Python shows the difference. The script kept its three lines, joined by backslash N, the newline character. The message became a single line, with spaces where the line breaks were. In workflows, you'll use the pipe almost every day.

Terminal
python3 -c "import yaml; d = yaml.safe_load(open('text.yml')); print(repr(d['script'])); print(repr(d['message']))"
'echo "Installing"\npip install -r requirements.txt\necho "Done"\n'
'This is one long sentence written over three lines in the file.\n'

Summary

The pipe keeps line breaks, which is perfect for several commands. The greater than sign folds lines into one. Next, a quiz on the foundations.

Key takeaways
  • | keeps lines
  • > folds lines
  • Used in run steps
Next up: Foundations Quiz — test yourself