Maven / GitLab CI Basics Interview Questions
What is the difference between cache and artifacts in GitLab CI?
Cache and artifacts are both mechanisms for persisting files across jobs, but they serve very different purposes and have different behaviours.
| Aspect | Cache | Artifacts |
|---|---|---|
| Purpose | Speed up jobs by reusing downloaded dependencies | Pass build outputs between stages/jobs |
| Storage | Runner's local disk or shared S3/GCS | GitLab server |
| Scope | Same runner, same branch (by cache key) | Any runner, same pipeline |
| Typical content | node_modules/, .m2/, pip cache | dist/, binaries, test reports |
| Reliability | Not guaranteed (may not exist) | Guaranteed (always transferred) |
| Downloaded by | Only the same runner (by default) | All jobs in later stages |
| Expiry | Configurable; can be cleared manually | expire_in (default: 30 days) |
# Cache example: reuse npm packages across pipeline runs cache: key: "$CI_COMMIT_REF_SLUG" # different cache per branch paths: - node_modules/ policy: pull-push # default: download at start, upload at end # Artifacts example: pass build output to next stage build: script: npm run build artifacts: paths: - dist/ # Best practice: use both together build-job: cache: paths: - node_modules/ # cache deps for speed script: - npm ci - npm run build artifacts: paths: - dist/ # pass output to deploy stage
Key insight: cache is not reliable for passing required build outputs between jobs - it is a performance optimisation only. For guaranteed file transfer between jobs, always use artifacts.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
