GH-200 - Consume and troubleshoot workflows - Section 2.3

Interpret matrix expansions and merged YAML anchors and aliases when analysing a workflow, and selectively re-run individual matrix jobs.

Trace the expanded job set produced by a matrix strategy and resolve YAML anchors, aliases, and merge keys to determine a workflow's final structure. Selectively re-run a single failing matrix job without rerunning every combination.

matrix expansionYAML anchorsre-run matrix jobmerge keys

Practice question for this objective

Free sampleConsume and troubleshoot workflowshard

A workflow defines an anchor on a defaults map and merges it into a step map with a merge key, while the step map also sets its own timeout-minutes value. When analysing the merged result, what timeout-minutes value applies to the step?

defaults: &base
  timeout-minutes: 10
  shell: bash
steps:
  - name: Build
    <<: *base
    timeout-minutes: 30
    run: make build
  • A10, because the merge key applies the anchored map last and its timeout-minutes overrides any value written directly on the step map during YAML resolution.
  • B40, because the merge key adds the anchored timeout-minutes to the value declared on the step map, producing a combined numeric total when the alias is expanded.
  • C30, because keys written directly on the mapping take precedence over keys supplied by the merge key, so the step value overrides the anchored default during resolution. Correct
  • Dan error, because a merge key cannot reference a key such as timeout-minutes that the receiving step map already defines, so the parser rejects the duplicate mapping.
Resolve a YAML merge key so that keys set directly on a mapping override the defaults supplied by the merged anchor. The merge key inserts the anchored map as a source of defaults, but the YAML merge specification gives precedence to keys defined directly on the receiving mapping. Because the step map sets timeout-minutes to 30 itself, that value is kept and the anchored 10 only fills keys the step does not declare, such as shell. Merge keys do not sum values and do not fault on an overridden key.

Why A is wrong: Tempting because the anchor is listed first, but a merge key only supplies defaults for keys the node does not already define, so the explicit 30 is kept and 10 never wins.

Why B is wrong: Tempting because both values are numeric, but merge keys never perform arithmetic on duplicate keys, they resolve to one value, so summing the two numbers is not how resolution works.

Why C is correct: A merge key fills in only the keys not already present on the node, so the directly written timeout-minutes of 30 takes precedence over the merged default of 10 from the anchor.

Why D is wrong: Tempting because duplicate plain keys are rejected, but a merge key is designed exactly for this case and silently defers to the local value, so no parse error is raised here.

See more GH-200 practice questions, answers explained.

More in this domain

Back to all Consume and troubleshoot workflows objectives, or the GH-200 cert hub.

Examworthy is not affiliated with or endorsed by GitHub. Original, blueprint-aligned practice material only.