Feedback

Chat Icon

Cloud Native CI/CD with GitLab

From Commit to Production Ready

Managing Artifacts in GitLab CI/CD: Data Sharing Between Jobs
52%

Managing Artifacts Dependencies: Selective Artifacts Using "dependencies"

The keyword artifacts is used to pass artifacts between jobs. However, all artifacts generated by a job are passed to the next ones. For example, in the following pipeline:

  • job-1 will generate an artifact called file1.txt.
  • job-2 will generate an artifact called file2.txt.
  • Finally, job-3 will fetch the artifacts generated by job-1 and job-2.

You can run the following command to test this pipeline:

cat <$HOME/todo/app/.gitlab-ci.yml && \
cd $HOME/todo/app && \
git add . && \
git commit -m "Artifacts example" && \
git push origin main
stages:
  - stage-1  
  - stage-2
  - stage-3

job-1:
  stage: stage-1
  script:
    - touch file1.txt
  artifacts:
    paths:
      - file1.txt

job-2:
  stage: stage-2
  script:
    - touch file2.txt
  artifacts:
    paths:
      - file2.txt

job-3:
  stage: stage-3
  script:
    - ls -l | grep "file1.txt" || echo "file1.txt not found"
    - ls -l | grep "file2.txt" || echo "file2.txt not found"
EOF

After the pipeline is triggered, you will see this output in the job-3 job:

[...]
Downloading artifacts for job-1 (8452994181)...
[...]
Downloading artifacts for job-2 (8452994182)...
[...]
$ ls -l | grep "file1.txt" || echo "file1.txt not found"
-rw-r--r-- 1 root root     0

Cloud Native CI/CD with GitLab

From Commit to Production Ready

Enroll now to unlock all content and receive all future updates for free.