I have a gitlab-ci pipeline in the first step of which npm dependencies are downloaded. These npm packages are also required in all subsequent stages of the pipeline. That’s why I wanted to take a closer look at the topic of caching in gitlab-ci.
Is there a key that makes the cache globally available for all stages belonging to the pipeline (of a specific branch) but generates it again on the next pipeline run?
cache:
key: $CI_COMMIT_REF_SLUG
The cache key should be unique for each pipeline run in the same branch.
>Solution :
You can use the $CI_PIPELINE_ID variable as the cache key to make the cache available for all stages belonging to the pipeline of a specific branch. Also it’s a unique identifier for each pipeline run, which makes it ideal for use as a cache key.