GitLab CI "yaml invalid: did not find expected key" in CI
GitLab could not parse .gitlab-ci.yml as YAML at all. "did not find expected key" means a mapping is mis-indented: a key sits where the parser expected a continuation of the previous value, usually a wrong number of spaces.
What this error means
The pipeline fails before any job with "Invalid configuration format" and a YAML error like "did not find expected key" pointing at a line and column.
Invalid configuration format
(<unknown>): did not find expected key while parsing a block mapping at line 7 column 3Common causes
Inconsistent indentation
A key is indented with a different width than its siblings, so YAML reads it as part of the previous value rather than a new key.
A tab character instead of spaces
YAML forbids tabs for indentation. A stray tab makes the parser lose the mapping structure.
How to fix it
Fix indentation at the reported line
- Open the file at the line/column the error names.
- Align the key with its sibling keys using consistent two-space indentation.
- Replace any tabs with spaces, then re-run CI Lint.
test:
stage: test
script:
- pytest # keys under the job aligned at 2 spacesLint YAML locally before pushing
Run a YAML linter so structural errors surface before they reach the pipeline.
yamllint .gitlab-ci.ymlHow to prevent it
- Use two-space indentation consistently and never tabs.
- Configure your editor to show whitespace for YAML files.
- Validate with CI Lint or
yamllintbefore pushing.