Jobs and Stages Definition
You'll learn how to structure your GitLab pipeline by defining individual jobs and grouping them into ordered stages.
What Are Jobs and Stages?
In GitLab CI/CD, a job is a single unit of work—a specific task your pipeline executes, like compiling code, running tests, or deploying an application. A stage is a logical grouping that organizes related jobs and controls execution order.
Think of stages like assembly line stations in a factory: the "cutting" stage must finish before the "assembly" stage begins, which must complete before "quality inspection." Jobs within the same stage run in parallel (when resources allow), while stages execute sequentially—one stage must fully complete before the next begins.
How Stages Control Execution Order
In your .gitlab-ci.yml file, you define stages at the top level, then assign each job to a stage:
stages:
- build
- test
- deploy
build_job:
stage: build
script:
- echo "Building application"
test_job:
stage: test
script:
- echo "Running tests"
deploy_job:
stage: deploy
script:
- echo "Deploying application"
GitLab executes stages in the order you list them. All jobs in build complete before any test jobs start. If any job in a stage fails, subsequent stages typically won't run (unless configured otherwise).
Multiple Jobs, Same Stage
You can define multiple jobs in one stage—they'll run concurrently:
test_unit:
stage: test
script:
- echo "Unit tests"
test_integration:
stage: test
script:
- echo "Integration tests"
Both test jobs run simultaneously during the test stage, speeding up your pipeline.
Key Takeaway: Jobs define what to execute, stages define when and in what order—stages run sequentially while jobs within a stage run in parallel, creating an efficient, organized pipeline structure.