DevOps / GitLab CI Basics Interview Questions
What are GitLab CI/CD artifacts and how do you use them?
Artifacts are files and directories that a job produces and saves after it finishes. They serve two purposes: downloading results from the GitLab UI, and passing files between jobs in subsequent stages.
build-job: stage: build script: - npm ci - npm run build # creates dist/ directory artifacts: paths: - dist/ # save entire dist directory - coverage/report.html # save a specific file exclude: - dist/**/*.map # exclude sourcemap files expire_in: 1 week # auto-delete after 1 week (default: 30 days) when: always # save artifacts even if job fails test-job: stage: test script: - ls dist/ # artifacts from build-job are available here! - npm test dependencies: - build-job # explicitly specify which artifacts to download # JUnit test reports (display inline in MR UI) test-with-report: stage: test script: - pytest --junitxml=report.xml artifacts: reports: junit: report.xml
| when value | Behaviour |
|---|---|
| on_success (default) | Save artifacts only when job succeeds |
| on_failure | Save artifacts only when job fails (useful for debug files) |
| always | Save artifacts regardless of job result |
Automatic download: by default, jobs automatically download artifacts from all jobs in preceding stages. Use dependencies: [] to opt out, or list specific jobs to download from.
More Related questions...