Managing Artifacts in GitLab CI/CD: Data Sharing Between Jobs
53%
DAG Pipelines and Artifacts
As we have seen, we can run a pipeline in a particular order using the needs keyword. However, when a job uses needs, it will not automatically download the artifacts from the job it depends on. In order to enable this, don't forget to add the artifacts keyword to the job that generates the artifacts.
Here is a practical example, using our Python application, where we launch 3 tests after the build stage, each test will generate an artifact and trigger a report job:
cat <$HOME/todo/app/.gitlab-ci.yml && \
cd $HOME/todo/app && \
git add . && \
git commit -m "Add dependencies between jobs" && \
git push origin main
image: python:3.12
stages:
- build
- security
- code-quality
- unittest
- security-reports
- code-quality-reports
- unittest-reports
build:
stage: build
script:
- pip install -r requirements.txt
security:
stage: security
script:
- pip install -r requirements.txt
- pip install bandit==1.7.9
- bandit -r app -o bandit.txt
artifacts:
paths:
- bandit.txt
needs:
- build
flake8:
stage: code-quality
script:
- pip install -r requirements.txt
- pip install flake8==7.1.1
- flake8 --statistics \Cloud Native CI/CD with GitLab
From Commit to Production ReadyEnroll now to unlock all content and receive all future updates for free.
