How do cache and artifacts differ in the CI/CD process in GitLab?
sobes.tech AI
Answer from AI
In GitLab CI/CD, cache and artifacts serve different purposes:
-
Cache is a temporary storage used to speed up builds. It typically contains dependencies, compiled libraries, and other intermediate data, so they don't need to be downloaded or rebuilt with each pipeline run. Cache persists between different jobs and pipelines but is not meant for long-term storage.
-
Artifacts are build results that need to be saved after a job completes and possibly passed to subsequent stages or downloaded. For example, compiled binaries, test reports, logs. Artifacts are stored in GitLab and are accessible for download or use in other jobs within the same pipeline.
Example:
build_job:
script:
- ./gradlew build
cache:
paths:
- .gradle/
artifacts:
paths:
- build/libs/
expire_in: 1 week
Here, .gradle/ is cached to speed up the build, and build/libs/ is saved as an artifact for later use.