Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

GitLab rejects .gitlab-ci.yml because variables is not a map

Your error

variables config should be a hash1 more line it can show

Fix it fast

Most common cause, 1 of 2

The variables are written as a list with dashes

Remove the dashes so each variable becomes a key of the map.

Fix
# 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 build
Did this fix it?
Full steps for this cause: check, fix, verify

Short 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.

  • Applies to GitLab 19.6 (GitLab.com and Self-Managed), glab CLI ci lint
  • Updated
  • By Maaz Zindani, Senior Software Engineer

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.

Run this first
grep -n -A4 "variables:" .gitlab-ci.yml

Then find the line you see in this list and open its fix:

  1. 1The variables are written as a list with dashesThe lines under variables: start with - , for example - NODE_ENV: production or - name: NODE_ENV
  2. 2variables holds one string instead of name and value pairsThe 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 hash
  • jobs: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.

Check
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.

Fix
# 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 build

Verify

CI Lint reports the configuration as valid, and the next pipeline starts with the build job.

Verify
glab ci lint .gitlab-ci.yml

Confirmed by gitlab.com

Did this fix it?

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.

Check
grep -n -E "variables:[[:space:]]*[^[:space:]]" .gitlab-ci.yml

Fix

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.

Fix
variables:
  NODE_ENV: "production"

test:
  variables:
    NODE_ENV: "test"
  script: npm test

Verify

The pipeline editor shows no syntax error, and a job that runs echo $NODE_ENV prints the job's own value.

Verify
glab ci lint --dry-run

Confirmed by docs.gitlab.com

Did this fix it?

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.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.