How do you pass artifacts between jobs in GitLab CI?
Short answer
Declare the files under artifacts:paths in the job that makes them: GitLab uploads them when that job succeeds, and every job in a later stage downloads them into its working directory by default. To take only some jobs' artifacts, list those jobs under dependencies, or under needs, which also starts the job early and is the only way to use a job in the same stage. On Premium and Ultimate, needs:project fetches artifacts from another project's pipeline, and needs:pipeline:job from a parent pipeline.
One job builds dist/, a binary or a test report, and the next job needs it. Every GitLab CI job starts in a fresh working directory, so nothing carries over on its own: the job that makes the files declares them as artifacts, GitLab stores them, and the jobs that come after it download them.
How do you pass a file from one job to the next?
List it under artifacts:paths in the job that creates it, and put the job that uses it in a later stage:
stages:
- build
- test
build:
stage: build
script:
- npm ci
- npm run build
artifacts:
paths:
- dist/
expire_in: 1 week
test:
stage: test
script:
- ls dist/
- npm test
When build succeeds, the runner archives dist/ and uploads it to GitLab. When test starts, its runner downloads the archive and extracts it into the job’s working directory, so dist/ is at the same relative path. No extra keyword is needed: by default, a job gets the artifacts of every job in earlier stages.
What can go under artifacts:paths:
- Paths inside the project. They’re relative to the project directory,
$CI_PROJECT_DIR, and can’t link outside it. A file written to/tmpor~can’t be an artifact: write it into the project directory, or copy it there in the script. - Wildcards. Glob patterns such as
path/*xyz/*and**work. - Untracked files.
artifacts:untracked: trueadds every file Git doesn’t track, and ignores.gitignorewhile doing it. - Exclusions.
artifacts:excludedrops files from the archive, but it isn’t recursive: writebinaries/temp/**/*, notbinaries/temp/.
Which jobs download the artifacts?
It depends on two keywords, dependencies and needs, and they also differ in when the job starts:
| The later job has | It downloads artifacts from | It starts |
|---|---|---|
| Neither keyword | Every job in earlier stages | When the earlier stages finish |
dependencies: [build] |
Only build, which must be in an earlier stage |
When the earlier stages finish |
dependencies: [] |
No job | When the earlier stages finish |
needs: [build] |
Only build, which can be in the same stage |
As soon as build finishes |
needs: [{job: build, artifacts: false}] |
No job | As soon as build finishes |
needs: [] |
No job | As soon as the pipeline is created |
Don’t combine dependencies and needs in the same job.
When should you use dependencies?
Use dependencies when the job should keep the stage order but download less, for example a deploy job that needs the build output and none of the test reports:
deploy:
stage: deploy
dependencies:
- build
script:
- ./deploy.sh dist/
Every job it lists must be in an earlier stage. dependencies: [] downloads nothing, which saves time in jobs such as linters that only need the repository.
When should you use needs?
Use needs when the job should start as soon as the jobs it uses finish, or when it needs a file from a job in the same stage:
build_app:
stage: build
script: make app
artifacts:
paths:
- bin/app
test_app:
stage: test
needs: ["build_app"]
script: ./bin/app --self-test
test_app starts the moment build_app finishes, even while other build jobs are still running, and downloads only build_app’s artifacts. A needs array can list up to 50 jobs on GitLab.com, and 50 by default on GitLab Self-Managed.
Two details save a broken pipeline:
artifacts: falseon aneedsentry keeps the ordering and skips the download.optional: truefor a job thatrulessometimes leaves out. Without it, GitLab won’t create the pipeline:'unit_tests' job needs 'compile' job, but 'compile' does not exist in the pipeline.More on that in GitLab CI “configuration is invalid”.
Why doesn’t the next job see the files?
Run down this checklist against the two job logs:
- The job that makes them succeeded.
artifacts:whendefaults toon_success, so a failed job uploads nothing. Useon_failureoralwaysfor logs you want after a failure; evenalwaysuploads nothing when the job times out. - The path matched something.
No files to uploadin the log means the runner couldn’t find the file. Check the path, and that the script really writes it there. - The later job asks for it. With
dependenciesorneeds, a job gets artifacts only from the jobs it lists. - The two jobs aren’t in the same stage, unless the later one uses
needs. - The artifacts still exist. Otherwise the job stops with
This job could not start because it could not retrieve the needed artifacts.: they expired, the job that makes them wasn’t found, or the job lacks access.
The other artifact errors, such as size limits, are in GitLab CI artifacts not found.
How long do artifacts last?
expire_in sets the lifetime, such as expire_in: 1 week; a number without a unit is seconds. Without it, the instance’s default artifacts expiration applies, which is 30 days by default. Artifacts from the latest pipeline on each ref, and from the most recent successful pipeline, are kept regardless, unless you clear Keep artifacts from most recent successful jobs in the project’s Settings › CI/CD › Artifacts. To keep one job’s artifacts, select Keep on the job’s page.
Size is limited too: GitLab.com accepts up to 1 GB per archive, compressed, and on GitLab Self-Managed an administrator sets the limit.
How do you get artifacts from another project or pipeline?
Both of these are Premium and Ultimate features.
Another project’s pipeline: needs:project, which must have job, ref and artifacts, and can fetch from up to five jobs:
use_library:
stage: build
needs:
- project: mygroup/library
job: build-library
ref: main
artifacts: true
script:
- ls
The user running the pipeline needs at least the Reporter role in mygroup/library, or the project must be public. When a CI/CD job token makes the request, mygroup/library must also allow your project: see CI_JOB_TOKEN access to another project. needs:project can’t be used in the same job as trigger.
A parent pipeline, from a child: the parent passes its pipeline ID to the child, and the child job names the job it needs with needs:pipeline:job. The upstream job must have finished with success:
# .gitlab-ci.yml (parent)
build_artifacts:
stage: build
script:
- echo "This is a test artifact!" >> artifact.txt
artifacts:
paths:
- artifact.txt
deploy:
stage: deploy
trigger:
include:
- local: path/to/child-pipeline.yml
variables:
PARENT_PIPELINE_ID: $CI_PIPELINE_ID
# path/to/child-pipeline.yml (child)
test:
stage: test
script:
- cat artifact.txt
needs:
- pipeline: $PARENT_PIPELINE_ID
job: build_artifacts
If GitLab answers needs:need pipeline should be a string in a dynamic child pipeline, quote the ID: pipeline: "$PARENT_PIPELINE_ID". Triggering child and multi-project pipelines is in how to trigger a pipeline in another GitLab project.
Outside any pipeline: the API downloads the artifacts of a branch’s job by name, at https://gitlab.com/api/v4/projects/<project-id>/jobs/artifacts/main/download?job=build; replace download with raw/<path> to get one file.
Artifacts or cache?
They look alike in .gitlab-ci.yml, but they do different jobs:
| Artifacts | Cache | |
|---|---|---|
| For | Files a job builds that later jobs, or people, need | Dependencies, such as downloaded packages |
| Used by | Later stages of the same pipeline | Later jobs and later pipelines, if the dependencies are identical |
| Stored | In GitLab | Where the runner is installed |
| Kept after the pipeline | Yes, until they expire | Yes, for later pipelines |
Pass build output with artifacts, and keep node_modules or a Gradle cache in the cache.
On your phone
MergeBell shows each pipeline’s jobs grouped by stage and each job’s log, and you can retry or cancel a job, or play a manual one, on the free tier, so a No files to upload warning is readable on your phone as soon as the runner writes it. Downloading or browsing artifacts needs GitLab in a browser.
Frequently asked questions
Can a GitLab CI job use artifacts from a job in the same stage?
Only through needs. By default a job downloads the artifacts of jobs in earlier stages. List the same-stage job under needs, and the job waits for it to finish and downloads its artifacts.
What is the difference between dependencies and needs in GitLab CI?
dependencies only filters whose artifacts a job downloads, from jobs in earlier stages; the job still waits for the earlier stages. needs also changes when the job starts: as soon as the jobs it lists finish, even in the same stage. Don't use both in one job.
Why can't the next job find the files from my build job?
Usually one of five things: the build job failed, and artifacts upload only on success unless artifacts:when is on_failure or always; the path matched nothing ("No files to upload"); the path is outside the project directory; the next job's dependencies or needs leaves the build job out; or the artifacts expired, which stops the job with "This job could not start because it could not retrieve the needed artifacts."
Should I use cache or artifacts to share files between GitLab CI jobs?
Artifacts for files a job builds that later jobs in the same pipeline need, or that you want after the pipeline ends. Cache for dependencies such as downloaded packages, which later pipelines can reuse too. Artifacts are stored in GitLab; cache is stored where the runner is installed.
How do I download a job's artifacts outside the pipeline?
From the job's page, the pipeline list or Build › Artifacts in GitLab, or with the API by branch and job name: https://gitlab.com/api/v4/projects/<project-id>/jobs/artifacts/main/download?job=build. Add raw/<path> instead of download to get a single file.
Sources
- GitLab docs — Job artifacts
- GitLab docs — CI/CD YAML syntax reference: artifacts, dependencies, needs
- GitLab docs — Make jobs start earlier with needs
- GitLab docs — Downstream pipelines: fetch artifacts from an upstream pipeline
- GitLab docs — Troubleshooting job artifacts
- GitLab docs — Caching in GitLab CI/CD
Checked against these pages on 19 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.