TIL: YAML's special indicators > and | handle of multiline strings

David Viramontes

David Viramontes
|
means "literal block scalar", which produces a multiline string with no special formatting
run:
command: |
npm run dev
npm run test
translates to:
npm run dev\nnpm run test
The cool one I learned about today is >-
, a "folded block scalar". It preserves line breaks as spaces (folding them into a single line). The -
modifier tells YAML to "chomp" (remove) any trailing newlines at the end of the block.
Example YAML
services:
postgres:
image: postgres
restart: always
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
translates to
... --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5