YAML "did not find expected key" error in CI
The YAML parser was reading a mapping and, at the reported line, expected the next key: but found content at the wrong indentation instead. It reports "did not find expected key".
What this error means
A YAML load fails with "did not find expected key" and a line:column. The surrounding block has mismatched indentation between siblings.
yaml: line 10: did not find expected keyCommon causes
A sibling key indented differently from its neighbors
One key in a mapping is off by a space, so the parser cannot align it as a sibling and reports a missing key.
A list item indented under a scalar value
A - item placed where a key was expected (because indentation drifted) breaks the mapping structure.
How to fix it
Align sibling keys to the same column
- Open the file at the reported line and inspect the indentation of nearby keys.
- Make every sibling key start at the exact same column.
- Re-run the loader or
yamllintto confirm.
# wrong: 'image' is indented one space too far
spec:
containers:
- name: app
image: nginx
# right
spec:
containers:
- name: app
image: nginxLint indentation before CI
yamllint's indentation rule catches the misalignment that produces this parser error.
yamllint deployment.yamlHow to prevent it
- Keep a strict, consistent indentation step (2 spaces).
- Never use tabs in YAML.
- Run yamllint in a pre-commit hook.