MSBA-308 · Lesson 8 of 12 · 23 min
YAML reading questions
▶ Video coming soon A video version of this lesson is on the way.
Lena's practice assessment had told her something uncomfortable: most of her troubleshooting misses came from reading YAML wrongly, not from gaps in what she knew. On Wednesday of the second week Priya gave a whole session to reading. "In your editor, the extension underlines mistakes and you fix them in seconds," she said. "On the exam, a YAML file is a picture. You have to be the parser." Many GH-200 questions in every domain show a snippet and ask what it does, what it produces or why it fails. This lesson collects the reading skills those questions depend on.
Structure: mappings, lists and indentation
YAML is built from mappings, which are key and value pairs, and lists, whose items start with a dash. Indentation, always with spaces, decides what belongs to what. In a workflow, jobs is a mapping of job IDs; steps is a list; each step is a mapping. The commonest reading error is to attach a key to the wrong parent because of indentation. A key indented under a step belongs to that step; the same key one level out belongs to the job.
jobs:
build:
runs-on: ubuntu-latest
env:
STAGE: job
steps:
- name: First
run: echo "$STAGE"
- name: Second
env:
STAGE: step
run: echo "$STAGE"Environment variables follow the most specific level: a step's env overrides the job's, which overrides the workflow's. So the first step above prints job and the second prints step. A question that shows env at three levels and asks what a step prints is testing exactly this.
Types and quoting
YAML guesses types. Most of the time that is helpful; on an exam it is a trap. A value such as 3.10 is read as a number, and the number 3.10 is the same as 3.1, so a matrix entry of python-version: [3.9, 3.10] asks for Python 3.1, which does not exist. Quoting it as a string keeps it as written. Version numbers in matrices and inputs should be quoted when trailing zeros matter.
| As written | Read as | Why it matters |
|---|---|---|
| 3.10 | The number 3.1 | A version 3.10 becomes 3.1 unless quoted |
| '3.10' | The string 3.10 | Correct for version inputs |
| true | A boolean | Inputs to actions still arrive as strings |
| 'true' | A string | Compare with the string in expressions if the source is a string |
| run: | | A block that keeps line breaks | Each line is a separate shell command |
| run: > | A block that folds lines into one | Lines join with spaces into one command |
The two block styles matter for run steps. With a vertical bar, the script keeps its line breaks, so each line runs as its own command. With a greater-than sign, lines are folded into one long line separated by spaces, which can turn three commands into one confused one. A question that shows a multi-line run with the folded style and asks why only the first command seems to run is testing this.
Anchors, aliases and merge keys
The January 2026 outline names YAML anchors twice: authoring with them, and expanding and interpreting them when troubleshooting. An anchor, written with an ampersand and a name, marks a value so it can be reused. An alias, written with an asterisk and the name, inserts a copy of that value. A merge key, written as two less-than signs, merges an anchored mapping into the current mapping, and keys written beside it override the merged ones.
jobs:
test:
runs-on: ubuntu-latest
env: &common-env
NODE_ENV: test
TZ: America/Halifax
LOG_LEVEL: info
steps:
- run: npm test
e2e:
runs-on: ubuntu-latest
env:
<<: *common-env
LOG_LEVEL: debug
steps:
- run: npm run e2eTo read an anchored file, expand it in your head. The e2e job's env becomes NODE_ENV test, TZ America/Halifax and LOG_LEVEL debug, because the key written beside the merge overrides the merged value. An alias without a merge key, such as env: *common-env, copies the mapping exactly, with no chance to override. Anchors work only within a single file: a reusable workflow cannot see an anchor defined in its caller, and a second workflow file cannot alias the first.
Worked problem
What does the job see?
A workflow defines defaults: &linux-node at the first job's level with runs-on: ubuntu-latest and timeout-minutes: 15. The second job has <<: *linux-node and timeout-minutes: 30. What runs-on and timeout does the second job get?
Show solution
- The merge copies runs-on: ubuntu-latest and timeout-minutes: 15 into the second job.
- The second job also sets timeout-minutes: 30 directly.
- A key written beside a merge key overrides the merged value.
Answer: runs-on: ubuntu-latest and timeout-minutes: 30.
Expressions inside YAML
Expressions are written with the dollar-brace syntax inside YAML strings. Two reading rules come up often. First, an if key is always evaluated as an expression, so the braces are optional there: if: github.ref == 'refs/heads/main' works. Second, a value that starts with an exclamation mark, an asterisk or an ampersand can confuse YAML itself, so expressions such as a negated condition are often written inside braces or quotes for safety. When an exam snippet has an if with a leading exclamation mark and no braces or quotes, check whether the question is about a YAML parsing error.
Comparisons in expressions are loose about types. Strings are compared without regard to case, and a comparison between a number and a string converts the string. The practical consequence is that a boolean input read through github.event.inputs arrives as a string, so comparing it with true fails, while the same input read through inputs works. Lesson 3 met this as an authoring rule; here it reappears as a reading question.
Reading triggers and filters
Trigger blocks reward slow reading. branches and branches-ignore cannot both be used for the same event, nor can paths and paths-ignore. Branch filters on push apply to the branch pushed to; on pull_request they apply to the base branch the pull request targets, which surprises many readers. A push that includes tags is filtered by tags, not branches; if a push event lists only branches, pushes of tags alone do not trigger it. A schedule block is a list of cron entries, and each needs its own dash.
Worked problem
Will it run?
A workflow has on: pull_request: branches: [main] and paths: ['src/**']. A contributor opens a pull request from feature/maps into release, changing src/map.js. Does the workflow run?
Show solution
- For pull_request, the branches filter applies to the base branch.
- The base branch is release, not main.
- The paths filter matches, but both filters must pass.
Answer: No. The pull request targets release, so the branches filter for main does not match.
A reading routine
Priya gave Lena a short routine for any snippet question, and Lena wrote it at the top of her whiteboard for the exam.
Reading a full workflow under time pressure
Snippet questions are short, but some questions show a whole workflow of thirty or forty lines and ask a single thing about it. Reading every line with equal care wastes minutes. Lena learned to read the question first, decide which part of the file it concerns, and read that part closely while skimming the rest. A question about when the workflow runs needs the on block and nothing else. A question about what a step can access needs the permissions at workflow and job level, the env at each level and the step itself. A question about job order needs the needs keys and any if conditions on jobs.
name: Release
on:
push:
tags: ['v*']
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
outputs:
file: ${{ steps.pack.outputs.file }}
steps:
- uses: actions/checkout@v5
- id: pack
run: |
tar -czf site.tgz public
echo "file=site.tgz" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v4
with:
name: site
path: site.tgz
publish:
needs: build
if: github.ref_type == 'tag'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@v4
with:
name: site
- run: gh release create "$GITHUB_REF_NAME" "${{ needs.build.outputs.file }}"
env:
GH_TOKEN: ${{ github.token }}Worked problem
Four questions about one file
Using the release workflow above: does a push to main run it; what permission does the build job have on repository contents; can the publish job create a release; and why does publish download the artifact?
Show solution
- The only event is a push of tags matching v*. A push to main with no tag does not match, so it does not run.
- The build job has no permissions key, so it inherits the workflow's contents: read.
- The publish job sets its own permissions with contents: write, which creating a release needs; unlisted permissions are none, which is fine here.
- Jobs run on separate runners with fresh workspaces, so a file built in one job must be passed as an artifact to reach the next.
Answer: No; read; yes; because each job starts with an empty workspace.
The last point in that example catches many readers. Each job runs on its own runner, so nothing written to disk in one job exists in another. Outputs carry small strings between jobs; artifacts carry files. A question that shows a second job reading a file the first job built, with no artifact step in between, is describing a failure.
Contexts and where they are available
Not every context can be used everywhere. The github, needs, vars and inputs contexts are available in most places, but the secrets context cannot be used in an if condition on a job or a step directly, and the matrix context exists only inside a job that has a matrix. The env context is available in steps, but it cannot be used to choose a job's runner in runs-on. When a snippet uses a context somewhere unusual, check whether it is allowed there before reasoning about its value. A common workaround for testing whether a secret is set is to copy it into a job-level env value and test that in the step's if condition.
| Context | Typical use | Reading trap |
|---|---|---|
| github | Event, ref, actor, repository | github.event.inputs gives strings |
| inputs | Dispatch and reusable workflow inputs | Keeps declared types |
| needs | Outputs and results of earlier jobs | Only jobs listed in needs are visible |
| matrix | Current variant values | Exists only in a matrix job |
| secrets | Encrypted values | Not usable directly in if conditions |
| vars | Configuration variables | Plain text, not masked |
Practising with your own files
The quickest way to build reading speed is to read real workflows. Lena took five workflow files from Tidewater's repositories and, for each one, wrote down before looking anything up: which events start it, which jobs run in parallel, what permissions each job has, which values each step can see and what each job produces. Then she checked her answers against a run of the workflow. On the first file she made four mistakes, mostly about inherited permissions and env. By the fifth she made none. Reading files she already partly knew was easier than reading new ones, which made it a good warm-up before Priya's harder snippets.
She also practised the opposite direction: given a short description, such as run on pushes to main that change src, with read-only contents permission and a two-version matrix, she wrote the YAML from memory and then compared it with a working file. Writing forces the same precision as reading, and the mistakes she made while writing, such as forgetting the dash before a list item or putting the matrix under the job instead of under strategy, were exactly the traps the exam uses.
Comments and blank lines
Two last reading details are easy to forget. A hash sign starts a comment, so anything after it on a line is ignored, including what looks like a key or a value; an exam snippet may comment out a line and ask what happens. Blank lines have no meaning in YAML, so a gap between two steps does not end the steps list. Only indentation and dashes decide structure. Lena added both to her routine as a quick check at step 2, while tracing indentation.
Common mistakes
MistakeReading 3.10 in a matrix as version 3.10.
InsteadUnquoted, it is the number 3.1; quote versions.
MistakeUsing the folded block style for multi-command scripts.
InsteadUse the literal block style with a vertical bar.
MistakeAssuming an anchor in one workflow can be used in another.
InsteadAnchors and aliases work only inside one file.
MistakeReading branches on pull_request as the head branch.
InsteadIt filters the base branch the pull request targets.
MistakeIgnoring a key written beside a merge key.
InsteadKeys written beside the merge override the merged values.
Lena practised with ten snippets Priya had collected from Tidewater's own repositories, rewritten with deliberate traps. She timed herself: the first five took four minutes each, the last five under two. More importantly, she got nine right, and the one she missed was a folded block she read too quickly.
Summary and key terms
- Reading YAML accurately is tested in every domain.
- Indentation decides ownership; the most specific env wins.
- Quote version numbers; unquoted 3.10 is the number 3.1.
- The vertical-bar block keeps line breaks; the folded block joins lines.
- Anchors mark values, aliases copy them, merge keys merge mappings and nearby keys override.
- Anchors work only within one file.
- Branch filters on pull_request apply to the base branch.
- Mapping
- A set of key and value pairs in YAML.
- Anchor
- A marker, written with an ampersand, that names a value for reuse.
- Alias
- A reference, written with an asterisk, that inserts a copy of an anchored value.
- Merge key
- The two-less-than key that merges an anchored mapping into the current one.
- Literal block
- A multi-line string written after a vertical bar, keeping line breaks.
- Folded block
- A multi-line string written after a greater-than sign, joining lines with spaces.
Practice problems
Work each problem on paper first, then reveal the answer to check.
What does python-version: [3.9, 3.10] actually request?
Show answer
3.9 and 3.1, because unquoted 3.10 is read as the number 3.1.
Can a reusable workflow use an anchor defined in its caller?
Show answer
No; anchors work only within one file.
Which env value does a step see if the workflow, job and step all set the same name?
Show answer
The step's value.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.