How do I use needs in GitLab CI to run jobs out of stage order?
Short answer
Add needs: to a job with the names of the jobs it depends on, and it starts as soon as those jobs finish instead of waiting for every job in earlier stages. Use needs: [] to start a job the moment the pipeline is created, and needs:optional when a needed job is sometimes left out by rules, or pipeline creation fails with "'job' does not exist in the pipeline".
Add needs: to a job and list the jobs it actually depends on. GitLab then starts that job as soon as those jobs finish, instead of waiting for every job in every earlier stage:
test_app_A:
stage: test
needs: ["build_app_A"]
script: echo "Testing A..."
Here test_app_A runs the moment build_app_A succeeds, even if a slow build_app_B in the same build stage is still going. GitLab describes the result as a directed acyclic graph (DAG): jobs follow their dependencies, not the stage order. needs is available on every tier, on GitLab.com, Self-Managed and Dedicated.
Why do my jobs wait for the whole previous stage?
Because that’s the default. Without needs, every job in a stage must finish successfully before any job in a later stage starts. With build, test and deploy stages, nothing in test starts until all of build is done, even jobs that have nothing to do with the slow one.
GitLab’s docs use a two-app example. Six jobs, two independent paths:
stages: [build, test, deploy]
build_app_A:
stage: build
script: echo "Building A..."
build_app_B:
stage: build
script: echo "Building B..."
test_app_A:
stage: test
needs: ["build_app_A"]
script: echo "Testing A..."
test_app_B:
stage: test
needs: ["build_app_B"]
script: echo "Testing B..."
deploy_app_A:
stage: deploy
needs: ["test_app_A"]
script: echo "Deploying A..."
deploy_app_B:
stage: deploy
needs: ["test_app_B"]
script: echo "Deploying B..."
With needs, app A can be built, tested and deployed before app B’s build finishes. You can mix jobs that use needs with ordinary staged jobs in the same pipeline.
How do I start a job immediately?
Give it an empty array. needs: [] starts the job as soon as the pipeline is created, without waiting for other jobs or stages:
lint_code:
stage: test
needs: []
script: echo "Linting code..."
This suits linters and scanners that only read the source code. The job still shows in the test column of the pipeline graph, but it runs from the first second. Jobs in the .pre stage also start immediately, so a pipeline with both starts them all together.
Which needs pattern do I want?
The docs name four shapes. Pick the one that matches how your jobs really depend on each other:
| Pattern | What it does | needs setup |
|---|---|---|
| Fan-out | One job feeds several | each test job: needs: ["build"] |
| Fan-in | Several jobs feed one | deploy: needs: ["test_frontend", "test_backend"] |
| Diamond | Fan-out, then fan-in | tests need build; deploy needs every test |
| Immediate start | No dependencies | needs: [] |
A fan-in job waits for every job in its list, and only those. Anything not listed can still be running when it starts.
Can I drop stages entirely?
Yes. You can leave out stage and stages and order the pipeline with needs alone. Jobs without a stage keyword land in the default test stage:
compile:
script: echo "Compiling..."
unit_tests:
needs: ["compile"]
script: echo "Running unit tests..."
integration_tests:
needs: ["compile"]
script: echo "Running integration tests..."
package:
needs: ["unit_tests", "integration_tests"]
script: echo "Packaging..."
The default pipeline view then shows every job in one test column. To see the real order, open the pipeline’s details page, select Job dependencies, and optionally turn on Show dependencies to draw the lines between linked jobs. A job can also need a job in its own stage, so you don’t need stages to express order at all.
Why does my pipeline fail with “does not exist in the pipeline”?
A job in your needs list wasn’t added to this pipeline. GitLab refuses to create the pipeline and shows an error like:
'unit_tests' job needs 'compile' job, but 'compile' does not exist in the pipeline.
The usual cause is rules, only or except on the needed job: on this branch, tag or pipeline source the job’s rules don’t match, so it’s left out, but the job that needs it is still there. You have two fixes.
Make the dependency optional, so it’s ignored when the job is missing:
compile:
stage: build
rules:
- if: $COMPILE == "true"
script: echo "Compiling..."
unit_tests:
stage: test
needs:
- job: "compile"
optional: true
script: echo "Running unit tests..."
Or give both jobs the same rules, so they always appear together:
build:
stage: build
rules:
- if: $BUILD == "true"
script: echo "Building..."
test:
stage: test
rules:
- if: $BUILD == "true"
needs: ["build"]
script: echo "Testing..."
Use optional: true when the job should run with or without the other one, like a deploy that waits for optional extra tests if they exist. Use matching rules when the job makes no sense without its dependency. When you use optional: true and the needed job does exist, the job still waits for it.
Which artifacts does a job with needs download?
Only the artifacts of the jobs in its needs list. A normal job downloads artifacts from all jobs in earlier stages; a job with needs can start before those stages finish, so GitLab limits it to what it named. If a file you expect is missing, check that the job that produces it is in the list.
To skip artifacts from a needed job you only wait on, set artifacts: false. The default is true:
test-job2:
stage: test
needs:
- job: build_job2
artifacts: false
With needs: [] the job depends on nothing, so it downloads no artifacts from earlier jobs.
How does needs work with parallel and matrix jobs?
If you need a job that uses parallel, your job depends on every job created from it, not just one, and downloads artifacts from all of them by default. When those artifacts share a file name, they overwrite each other and only the last one downloaded is kept. To depend on just some of the generated jobs, use needs:parallel:matrix and name the matrix values you want. Our parallel:matrix guide covers that syntax.
What are the limits and gotchas?
A short checklist before you push:
- 50 jobs per needs list. That’s the limit on GitLab.com. Self-Managed and Dedicated default to 50 too, and an administrator can change it in the Admin area’s CI/CD limits.
- Same-stage needs are fine. A job can need a job in its own stage.
- Rules must line up. A needed job filtered out by
rules,onlyorexceptbreaks pipeline creation unless the entry isoptional: true. - Artifacts come only from listed jobs. Add the producing job to
needs, or useartifacts: falsewhen you only want the ordering. needs:projectandneeds:pipelineare different keywords. They don’t set job order:needs:projectfetches artifacts from other pipelines, andneeds:pipelinemirrors an upstream pipeline’s status.- Other config errors look similar. Our guide to CI “configuration is invalid” errors lists the other common messages.
How do I check which job a pipeline is waiting on?
On the pipeline details page, select Job dependencies and turn on Show dependencies: the lines show exactly which jobs each job waits for. When you’re away from your desk, MergeBell lists a pipeline’s jobs grouped by stage with failed and manual jobs highlighted, so you can see which dependency failed, read its log tail and retry it from your phone.
Frequently asked questions
What does needs do in GitLab CI?
It lists the jobs a job depends on. The job starts as soon as those jobs finish, even if other jobs in earlier stages are still running, so the pipeline runs as a directed acyclic graph (DAG) instead of stage by stage.
What does needs: [] mean?
An empty array makes the job start as soon as the pipeline is created, without waiting for any other job or stage. It's the usual choice for lint jobs and scanners that only need the source code.
How do I fix "job needs 'x' job, but 'x' does not exist in the pipeline"?
The needed job was left out of this pipeline by rules, only or except. Either add optional: true to that entry in needs, so it's ignored when the job is missing, or give the needed job rules that always match whenever the dependent job runs.
Can a job need a job in the same stage?
Yes. GitLab lets needs refer to jobs in the same stage as the job you're configuring, and you can drop stages entirely and order a pipeline with needs alone.
How many jobs can one job need?
Up to 50 on GitLab.com. On GitLab Self-Managed and GitLab Dedicated the default is also 50, and an administrator can change it in the CI/CD limits in the Admin area.
Sources
Checked against these pages on 22 November 2026. GitLab changes quickly — if something here no longer matches, tell us and we will fix it.
Do this from your phone with MergeBell
Free for the whole review loop: the To-Do inbox, diffs and line comments, approve and merge, pipelines with retry, and push alerts for your To-Dos. Works with gitlab.com and self-managed GitLab 16.0+.
Get MergeBell for iPhoneGet MergeBell for Android
On the App Store for iOS 26 or later and on Google Play for Android 12 or later. An independent app, not affiliated with GitLab Inc.