Understanding the hierarchy, precedence, sequencing, and parallelism in GitLab CI/CD pipelines is crucial to mastering how your jobs run, how to optimize them, and how GitLab decides what to execute and when.
Hereโs a complete and up-to-date (GitLab 18.0, May 2026) breakdown of the GitLab pipeline execution model:
๐งฑ 1. ๐ GitLab CI/CD Execution Hierarchy
โค Pipeline (Top-Level Entity)
A single run of your .gitlab-ci.yml file. Triggered by:
- Push/merge/tag
- Schedule
- Manual trigger
- API call
โค Stages (Sequential Execution Layer)
Defines the order of execution โ each stage completes fully before the next begins.
stages:
- lint
- test
- build
- deploy
โค Jobs (Inside Each Stage)
All jobs within a stage run in parallel, provided runners are available.
lint:
stage: lint
script: npm run lint
unit_test:
stage: test
script: npm test
โค Steps inside a Job
Each jobโs script: section contains commands that run sequentially inside the job’s shell or container.
๐ 2. Pipeline Execution Flow
Pipeline
โโโ Stage 1: lint
โ โโโ job: lint_a (parallel)
โ โโโ job: lint_b (parallel)
โโโ Stage 2: test
โ โโโ job: unit_tests
โ โโโ job: integration_tests
โโโ Stage 3: build
โ โโโ docker_build
โโโ Stage 4: deploy
โโโ job: staging_deploy
โโโ job: prod_deploy (manual)
โฑ๏ธ 3. Job Precedence & Order of Execution
โ Within a Stage:
- Jobs run in parallel
- No strict order unless using
needs:(see below)
โ Between Stages:
- Sequential: Stage 2 starts only if all Stage 1 jobs succeed
โก 4. How to Run Jobs in Parallel or Control Order
๐น Parallel Jobs
Jobs in the same stage naturally run in parallel. Example:
test_backend:
stage: test
script: run backend tests
test_frontend:
stage: test
script: run frontend tests
๐น Needs: (Run jobs out-of-order / faster)
Allows stage-skipping and job-level dependency. Ideal for reducing pipeline time.
unit_test:
stage: test
script: run tests
docker_build:
stage: build
script: build docker
needs: [unit_test] # Doesn't wait for whole test stage
Code language: PHP (php)
๐น Dependencies (Job artifact consumption, older method)
Specify jobs that must complete before current job can use their artifacts.
deploy:
stage: deploy
dependencies: [build]
Code language: CSS (css)
๐ Use
needs:for parallel dependency-based optimization
๐ฆ Usedependencies:to pass artifacts
๐งช 5. Conditional Execution (Job-Level Control)
๐ธ Rules
Recommended way to control job execution with complex conditions.
job_a:
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
Code language: JavaScript (javascript)
๐ธ only/except (Deprecated in favor of rules)
job_b:
only:
- branches
- tags
๐ฏ 6. Extended Structures
| Structure | Purpose | Notes |
|---|---|---|
| Parent-Child Pipelines | Modularize pipelines (include from other .yml) | Ideal for monorepos |
| Multi-project Pipelines | Trigger another projectโs pipeline | Good for microservice chaining |
| Includes | Reuse YAML templates | From same repo or remote |
๐ 7. Visual: GitLab CI/CD Execution Hierarchy
Pipeline
โโโ Stages (sequential)
โ โโโ Jobs (parallel unless controlled)
โ โ โโโ Scripts (sequential commands)
โ โ โโโ Artifacts/Needs/Dependencies
โโโ Includes / Child Pipelines (optional)
โโโ Triggered Pipelines (optional)
โ Summary: Controlling Flow & Parallelism
| Control Mechanism | Used For |
|---|---|
stages: | Define sequential job groupings |
needs: | Define parallel dependencies |
rules: | Fine-grained control of job triggers |
when: | Delay, manual, or conditional jobs |
only/except | Basic conditions (legacy) |
dependencies: | Artifact-based job dependencies |
trigger: | Trigger child or multi-project pipelines |
Iโm a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow , and SEO strategies at Wizbrand.
Do you want to learn Quantum Computing?
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at WIZBRAND
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals