Skip to content
Latchkey

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.

Pipeline Editor / CI lint
Invalid configuration format
(<unknown>): did not find expected key while parsing a block mapping at line 7 column 3

Common 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

  1. Open the file at the line/column the error names.
  2. Align the key with its sibling keys using consistent two-space indentation.
  3. Replace any tabs with spaces, then re-run CI Lint.
.gitlab-ci.yml
test:
  stage: test
  script:
    - pytest        # keys under the job aligned at 2 spaces

Lint YAML locally before pushing

Run a YAML linter so structural errors surface before they reach the pipeline.

Terminal
yamllint .gitlab-ci.yml

How 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 yamllint before pushing.

Frequently asked questions

What causes ""did not find expected key""?
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.
How do I fix "did not find expected key"?
Fix indentation at the reported line

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card