GitLab rejects .gitlab-ci.yml because variables is not a map
Fix it fast
Most common cause, 1 of 2The variables are written as a list with dashes
Remove the dashes so each variable becomes a key of the map.
# wrong
build:
variables:
- NODE_ENV: production
- API_URL: https://api.example.com
script: npm run build
# right
build:
variables:
NODE_ENV: "production"
API_URL: "https://api.example.com"
script: npm run buildShort answer
GitLab CI reports variables config should be a hash when a variables block is not a YAML map of names to values, usually a list with dashes or one KEY=value string. Rewrite it as indented NAME: "value" lines with no dash, in jobs, defaults and rules alike, then run CI Lint. Applies to GitLab 19.6.
Which cause do you have?
Print every variables block with a few lines after it. A line that starts with a dash under variables is cause 1; a value on the same line as variables:, or text with an equals sign, is cause 2.
grep -n -A4 "variables:" .gitlab-ci.ymlThen find the line you see in this list and open its fix:
- 1The variables are written as a list with dashes
The lines under variables: start with - , for example - NODE_ENV: production or - name: NODE_ENV - 2variables holds one string instead of name and value pairs
The block looks like variables: "NODE_ENV=production" or variables: NODE_ENV=production on a single line
What does the error look like?
variables config should be a hashjobs:build:variables config should be a hash
Cause 1 of 2
The variables are written as a list with dashes
You seeThe lines under variables: start with - , for example - NODE_ENV: production or - name: NODE_ENV
Check
GitLab parses each variables block into an entry whose only accepted type is a hash, so a YAML list fails with variables config should be a hash. The same entry class is used for variables inside rules:, so a list there fails the same way with a longer path in front.
grep -n -A4 "variables:" .gitlab-ci.yml | grep -E "^[0-9]+-[[:space:]]+- "Fix
Remove the dashes so each variable becomes a key of the map. The docs describe the supported values as variable name and value pairs; names use letters, digits and underscores, and each value must be a string, so quote it.
# wrong
build:
variables:
- NODE_ENV: production
- API_URL: https://api.example.com
script: npm run build
# right
build:
variables:
NODE_ENV: "production"
API_URL: "https://api.example.com"
script: npm run buildVerify
CI Lint reports the configuration as valid, and the next pipeline starts with the build job.
glab ci lint .gitlab-ci.ymlConfirmed by gitlab.com
Cause 2 of 2
variables holds one string instead of name and value pairs
You seeThe block looks like variables: "NODE_ENV=production" or variables: NODE_ENV=production on a single line
Check
A shell-style assignment is a single YAML string, not a map, so the type check on the variables entry rejects it in the same way. The equals sign has no meaning in GitLab's variables syntax; the colon and indentation do.
grep -n -E "variables:[[:space:]]*[^[:space:]]" .gitlab-ci.ymlFix
Split the string into one NAME: "value" line per variable, indented under variables:. Put the shared ones at the top level, where they act as defaults for every job unless a job defines the same name.
variables:
NODE_ENV: "production"
test:
variables:
NODE_ENV: "test"
script: npm testVerify
The pipeline editor shows no syntax error, and a job that runs echo $NODE_ENV prints the job's own value.
glab ci lint --dry-runConfirmed by docs.gitlab.com
How do I stop it coming back?
- Run glab ci lint in a pre-commit hook or as the first CI job on merge requests that touch .gitlab-ci.yml.
- Edit pipeline files in GitLab's pipeline editor, which checks the configuration syntax automatically.
- Keep shared variables in one top-level block instead of copying blocks between jobs, so one wrong shape cannot spread.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.