YAML Syntax Cheat Sheet: Types, Anchors & Multiline
YAML types, multiline blocks, and anchors in one reference (plus the gotchas).
The syntax you use writing CI and config YAML, and the traps to avoid.
Structure
config.yaml
key: value # mapping
list: # sequence
- one
- two
nested:
inner: value
inline_list: [a, b]
inline_map: {x: 1}Multiline strings
| Block | Behavior |
|---|---|
| | (literal) | Keeps newlines |
| > (folded) | Folds newlines to spaces |
| |- / >- | Strip trailing newline |
| |+ / >+ | Keep trailing newlines |
Anchors & aliases
anchors
defaults: &defaults
retries: 3
timeout: 30
job_a:
<<: *defaults # merge
name: aGotchas
| Pitfall | Fix |
|---|---|
| Tabs for indent | Use spaces only |
| yes/no/on/off parsed as bool | Quote "no" if you mean string |
| Unquoted version 1.0 -> float | Quote "1.0" |
| Leading 0 -> octal/string | Quote it |
Key takeaways
- Indentation is spaces only - tabs are a hard error.
- | keeps newlines; > folds them into spaces.
- Quote ambiguous scalars like no, yes, on, and versions.
Related guides
GitLab CI Keywords Cheat Sheet: Every .gitlab-ci.yml KeywordA GitLab CI keywords cheat sheet - job, rules, needs, cache, artifacts, extends, variables, and the .gitlab-c…
GitHub Actions Cheat Sheet: Syntax, Contexts & CommandsA GitHub Actions cheat sheet - triggers, jobs, steps, contexts, expressions, caching, matrix, and the workflo…
Terraform CLI Cheat Sheet: init, plan, apply & stateA Terraform CLI cheat sheet - init, plan, apply, destroy, state, workspace, and fmt commands for everyday inf…