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

Parallel Job Execution

Running jobs in parallel with matrix configurations to speed up test execution.

Parallel Job Execution

What you'll learn: How to run multiple job instances simultaneously using matrix configurations to dramatically reduce your pipeline execution time.

The Core Concept

In GitLab CI/CD, parallel job execution allows you to split a single job into multiple instances that run at the same time. Instead of running tests sequentially (one after another), you can divide them across multiple runners, cutting your total pipeline time proportionally.

Think of it like a restaurant kitchen: instead of one cook preparing all ten orders sequentially (taking 100 minutes), you hire five cooks who each handle two orders simultaneously (taking just 20 minutes total).

How It Works

You use the parallel keyword to specify how many instances of a job should run. GitLab automatically sets environment variables (CI_NODE_INDEX and CI_NODE_TOTAL) that each instance can use to determine which subset of work it should handle.

test:
  stage: test
  script:
    - echo "Running test slice $CI_NODE_INDEX of $CI_NODE_TOTAL"
    - npm run test -- --shard=$CI_NODE_INDEX/$CI_NODE_TOTAL
  parallel: 5

This creates five identical jobs (test 1/5, test 2/5, etc.) that run simultaneously. Each instance knows its position and can divide the test suite accordingly.

Real-World Benefits

If you have 1,000 tests taking 50 minutes to run, splitting them across 5 parallel jobs could reduce execution time to around 10 minutes (plus overhead). This is especially valuable for large test suites, multi-platform builds, or any compute-intensive job that can be divided into independent chunks.

Key Takeaway: The parallel keyword splits a single job into multiple concurrent instances, dramatically reducing pipeline execution time by distributing work across multiple runners simultaneously.