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

Pipeline Stages and Job Ordering

Organize jobs into stages to control execution order and enable parallel execution within stages.

Pipeline Stages and Job Ordering

What You'll Learn

You'll learn how to organize GitLab CI/CD jobs into stages that control execution order and enable parallel execution for faster pipelines.

Understanding Stages

In GitLab CI/CD, stages act like floors in a building—each floor must be completed before moving to the next, but multiple rooms (jobs) on the same floor can be worked on simultaneously.

By default, GitLab provides stages like build, test, and deploy, but you can define your own. Jobs assigned to the same stage run in parallel (if multiple runners are available), while stages themselves execute sequentially.

How Stage Ordering Works

Stages are defined at the top of your .gitlab-ci.yml file and execute in the order you list them:

stages:
  - build
  - test
  - deploy

Jobs are then assigned to stages using the stage: keyword. If a job doesn't specify a stage, it defaults to test.

compile_app:
  stage: build
  script:
    - make build

unit_tests:
  stage: test
  script:
    - make test

integration_tests:
  stage: test
  script:
    - make integration

deploy_production:
  stage: deploy
  script:
    - make deploy

In this example, compile_app runs first. Once it completes successfully, both unit_tests and integration_tests run in parallel. Only after all test jobs pass does deploy_production execute.

Why This Matters

This stage-based approach prevents wasting time on expensive deployment tasks if earlier tests fail, while maximizing speed by running independent jobs simultaneously.

Key Takeaway: Stages control the sequential flow of your pipeline, while jobs within the same stage run in parallel, giving you both order and efficiency in your CI/CD process.