Workflows nest data a lot. A job contains steps, which is a list, and each step contains keys, which is a map. Let's get comfortable with lists of maps, because you'll see them in every workflow.
Steps is a list, so each item starts with a dash. And each item is a map, with keys like name and run. The keys of one item line up under each other. This one shape, a list of maps, is how every workflow's steps are written. The short form, with square brackets, is a list on one line.
steps.ymlyaml
steps: - name: Say hello run: echo hello - name: Show the date run: date - name: Pick branches branches: [main, release]
Python shows that steps is a list of three maps. And with a small loop, we print each step's name. Notice the last step's branches became a proper list, even though it was written on one line, with square brackets.
Terminal
python3 -c "import yaml; d = yaml.safe_load(open('steps.yml')); print(type(d['steps']).__name__, len(d['steps']))"list 3python3 -c "import yaml; [print('-', s['name']) for s in yaml.safe_load(open('steps.yml'))['steps']]"- Say hello- Show the date- Pick branchespython3 -c "import yaml; print(yaml.safe_load(open('steps.yml'))['steps'][2]['branches'])"['main', 'release']
A dash starts a list item, and a list item can be a map with its own keys. Square brackets write a list on one line. Next, the YAML mistakes that catch everyone.
Key takeaways
- starts an item
Lists of maps
[a, b] on one line
Next up: YAML Gotchas — tabs, colons, and surprises