Managing Artifacts in GitLab CI/CD: Data Sharing Between Jobs
54%
Choosing When to Download Artifacts
Let's simplify the DAG example above and imagine we have 3 jobs: job_1, job_2, and job_3.
job_2andjob_3depend onjob_1.- The second job,
job_2, needs the artifacts generated byjob_1, butjob_3does not.
Here is how you can manage this:
job_1:
script:
- echo "This is job 1"
- echo "some data" > artifact1.txt
artifacts:
paths:
- artifact1.txt
job_2:
needs:
- job: job_1
script:
- echo "This is job 2"
- cat artifact1.txt
job_3:
needs:
- job: job_1
script:
- echo "This is job 3"
There is no problem with our pipeline, however, we are downloading the artifact1.txt file in the job_3 job, even though it is not needed. This can be time-consuming if the artifact is large. To avoid this, you can add artifacts: false to the job_3 job. This way, the artifact will not be downloaded even though it is generated by job_1. Here is how you can achieve this:
job_3:
needs:
-Cloud Native CI/CD with GitLab
From Commit to Production ReadyEnroll now to unlock all content and receive all future updates for free.
