Course contentsShow
← Cloud and Infrastructure
Lesson 1762 of 2,98936. GitLab CI/CDFree lesson

Matrix Builds and Parallel Execution

Use matrix and parallel keywords to run jobs with multiple variable combinations efficiently.

Matrix Builds and Parallel Execution

You'll learn how to multiply your testing coverage across many configurations while speeding up pipeline execution in GitLab CI/CD.

What Are Matrix Builds?

Matrix builds let you run the same job multiple times with different variable combinations automatically. Instead of manually writing five nearly identical jobs to test across Python 3.8, 3.9, 3.10, 3.11, and 3.12, you define the job once and let GitLab create all variations for you.

Think of it like a spreadsheet: you define the rows (variables) and columns (values), and GitLab fills in every cell by running each combination as a separate job instance.

The parallel:matrix Keyword

GitLab uses parallel with a matrix configuration to generate multiple job instances:

test:
  parallel:
    matrix:
      - VERSION: ['3.8', '3.9', '3.10']
        OS: ['ubuntu', 'alpine']
  script:
    - echo "Testing Python $VERSION on $OS"
    - run-tests

This creates 6 jobs automatically (3 versions × 2 operating systems), all running simultaneously if you have enough runners.

Combining with Standard Parallel

You can also use parallel with a simple number to duplicate a job without variables—useful for load testing or splitting test suites:

load-test:
  parallel: 5
  script:
    - run-load-test-instance

This spawns 5 identical jobs, each accessible via CI_NODE_INDEX and CI_NODE_TOTAL variables for distribution logic.

Key Takeaway: Matrix builds multiply your job across variable combinations automatically, while numeric parallel duplicates jobs for sheer throughput—both accelerate pipelines by running work concurrently instead of sequentially.