How do I use parallel:matrix in GitLab CI?

By Melih Toksari, developer of MergeBell · Updated · 5 min read

Short answer

Add parallel:matrix to a job with a list of variable sets: GitLab creates one job per combination, named like build: [amd64, alpine], with each value available as a CI/CD variable. Values can be a string or an array of strings, identifiers use only letters, numbers and underscores, and one job can't produce more than 200 combinations.

Use parallel:matrix when the same job has to run once per Node version, per architecture, per cloud provider or per service. You list the variable values; GitLab creates one job per combination and runs them in parallel in the same pipeline. Each copy sees its values as ordinary CI/CD variables.

test:
  image: node:${NODE_VERSION}
  script:
    - npm ci
    - npm test
  parallel:
    matrix:
      - NODE_VERSION: ["20", "22", "24"]

That creates three jobs: test: [20], test: [22] and test: [24].

How does GitLab expand a matrix?

Each item under matrix: is one set. Inside a set, GitLab multiplies the arrays; across sets, it adds the results. This is the example from the YAML reference:

deploystacks:
  stage: deploy
  script:
    - bin/deploy
  parallel:
    matrix:
      - PROVIDER: aws
        STACK:
          - monitoring
          - app1
          - app2
      - PROVIDER: [gcp, vultr]
        STACK: [data, processing]
  environment: $PROVIDER/$STACK

The first set gives 1 × 3 = 3 jobs, the second 2 × 2 = 4, so seven jobs in all:

Job name PROVIDER STACK
deploystacks: [aws, monitoring] aws monitoring
deploystacks: [aws, app1] aws app1
deploystacks: [aws, app2] aws app2
deploystacks: [gcp, data] gcp data
deploystacks: [gcp, processing] gcp processing
deploystacks: [vultr, data] vultr data
deploystacks: [vultr, processing] vultr processing

Use a set per “shape” of combination instead of one big set when not every value pairs with every other.

What are the limits?

  • Identifiers (the variable names) can use only letters, numbers and underscores.
  • Values must be a string or an array of strings. Quote numbers that look like versions ("3.0"), or YAML may read them as numbers.
  • 200 permutations at most per job.
  • Job names get the matrix values appended. Long values can push a name past the 255-character limit.
  • Runners: the jobs only run in parallel if you have several runners, or one runner configured to run jobs concurrently. Extra jobs wait as pending.
  • Instance job limit: a pipeline can fail with job_activity_limit_exceeded if creating it would exceed the instance’s limit on jobs across all active pipelines.

Why do some matrix jobs disappear?

Two causes cover most cases.

Identical values overwrite each other. GitLab builds job names from values, not variable names. Here the OS2 jobs end up with the same names as the OS jobs and replace them:

test:
  parallel:
    matrix:
      - OS: [ubuntu]
        PROVIDER: [aws, gcp]
      - OS2: [ubuntu]
        PROVIDER: [aws, gcp]

You can’t create two matrix configurations that differ only in variable names. Make the values differ, or split them into two jobs.

Rules run per matrix job. GitLab evaluates rules separately for each generated job, with that job’s values, which is useful on purpose:

test:
  script: echo "Building $ARCH"
  parallel:
    matrix:
      - ARCH: [amd64, arm64]
        SKIP: ["false", "true"]
  rules:
    - if: $SKIP == "true"
      when: never
    - when: on_success

Only the jobs with SKIP set to "false" are created. One catch: rules:if doesn’t do nested expansion. If a matrix value is $GLOBAL_FILE, the expression compares the literal string $GLOBAL_FILE, not its value. Matrix values also work in rules:changes and rules:exists paths, which suits monorepos:

test:
  script: echo "Testing $SERVICE in $ENV"
  parallel:
    matrix:
      - SERVICE: [api, web]
        ENV: [dev, prod]
  rules:
    - changes:
        - config/$SERVICE/$ENV/**/*

If rules:changes itself misbehaves, see GitLab CI rules:changes not working.

How do I make a job need one matrix job?

Use needs with parallel:matrix and list the values you want:

linux:rspec:
  stage: test
  needs:
    - job: linux:build
      parallel:
        matrix:
          - PROVIDER: aws
            STACK: app1
  script: echo "Running rspec on linux..."

linux:rspec starts as soon as linux:build: [aws, app1] finishes, without waiting for the other build jobs.

For dependencies, write the generated job name, in quotes, which the docs say are required:

deploy:
  stage: deploy
  dependencies:
    - "ruby: [2.7, aws]"
  script: echo hello

If a needs entry names a job that rules didn’t create, GitLab won’t create the pipeline at all; GitLab CI “configuration is invalid” covers that error, and passing artifacts between jobs covers needs versus dependencies in general.

How do I map two matrices one to one?

Use matrix expressions instead of spelling out every combination. $[[ matrix.IDENTIFIER ]] refers to the current job’s own matrix value:

linux:test:
  parallel:
    matrix:
      - PROVIDER: aws
        STACK: [monitoring, app1, app2]
  needs:
    - job: linux:build
      parallel:
        matrix:
          - PROVIDER: ['$[[ matrix.PROVIDER ]]']
            STACK: ['$[[ matrix.STACK ]]']
  script: echo "Testing $PROVIDER/$STACK"

Now linux:test: [aws, app1] needs exactly linux:build: [aws, app1], and so on. Matrix expressions are resolved when the pipeline is created, do plain string replacement only, and can reference only matrix identifiers of the current job, not other CI/CD variables or inputs. To share one matrix between jobs, define it once with a YAML anchor (.build_matrix: &build_matrix) and reuse it.

Can each matrix job use a different runner?

Yes. Matrix values work in tags:

deploystacks:
  stage: deploy
  script:
    - bin/deploy
  parallel:
    matrix:
      - PROVIDER: aws
        STACK: [monitoring, app1]
      - PROVIDER: gcp
        STACK: [data]
  tags:
    - ${PROVIDER}-${STACK}
  environment: $PROVIDER/$STACK

Each job needs a runner with the matching tag (aws-monitoring, gcp-data), or it stays pending; GitLab job stuck in pending walks through that. A matrix also works on trigger jobs: with trigger: include: plus parallel:matrix, GitLab creates one child pipeline per combination, each with its own variables.

When should I use plain parallel instead?

When every copy should do the same thing on a different slice of the work, such as a long test suite. parallel: 3 creates test 1/3 to test 3/3, and each copy gets CI_NODE_INDEX and CI_NODE_TOTAL so your test runner can pick its share:

test:
  parallel: 3
  script:
    - bundle
    - bundle exec rspec_booster --job $CI_NODE_INDEX/$CI_NODE_TOTAL

Checklist before you push

  • Every identifier uses only letters, numbers and underscores.
  • Version-like values are quoted strings.
  • No two sets produce the same values.
  • Total combinations per job stay at or under 200.
  • dependencies entries are quoted generated names; needs uses parallel:matrix or matrix expressions.
  • Runner tags built from matrix values exist on a runner.
  • Validate in Build › Pipeline editor before you push.

A wide matrix makes the pipeline graph long. MergeBell lists a pipeline’s jobs grouped by stage with failed jobs highlighted, so on a phone you can open the one failing combination’s log tail and retry just that job.

Frequently asked questions

How many jobs can parallel:matrix create?

The number of permutations in one job can't exceed 200. The plain parallel: N form also accepts 1 to 200. If there are more jobs than free runners, the extra jobs wait as pending, and a pipeline can fail with job_activity_limit_exceeded if it would push the instance past its limit on jobs in active pipelines.

Why are some of my matrix jobs missing?

GitLab names matrix jobs from the values, not the variable names. Two matrix entries with the same values but different variable names produce identical job names, and the later ones overwrite the earlier ones. Rules can also drop jobs: GitLab evaluates rules separately for each matrix job with that job's values.

How do I make a job depend on one specific matrix job?

Use needs with job and parallel:matrix listing the values, for example needs: - job: linux:build, parallel: matrix: - PROVIDER: aws, STACK: app1. For dependencies, write the generated name in quotes, like "ruby: [2.7, aws]". For a 1:1 mapping between two matrix jobs, use matrix expressions such as '$[[ matrix.OS ]]'.

Can I use matrix variables in rules?

Yes, in rules:if, rules:changes and rules:exists. GitLab evaluates rules for each matrix job using its own values. Nested expansion isn't supported in rules:if: a value like $GLOBAL_FILE is compared as that literal string.

What's the difference between parallel: 5 and parallel:matrix?

parallel: 5 runs five identical copies named test 1/5 to test 5/5 and gives each CI_NODE_INDEX and CI_NODE_TOTAL, so your test tool can split the work. parallel:matrix runs one copy per combination of variable values, so each copy does something different.

Sources

Checked against these pages on 20 November 2026. GitLab changes quickly — if something here no longer matches, tell us and we will fix it.

Do this from your phone with MergeBell

Free for the whole review loop: the To-Do inbox, diffs and line comments, approve and merge, pipelines with retry, and push alerts for your To-Dos. Works with gitlab.com and self-managed GitLab 16.0+.

Get MergeBell for iPhoneGet MergeBell for Android

On the App Store for iOS 26 or later and on Google Play for Android 12 or later. An independent app, not affiliated with GitLab Inc.