When two pipelines are executed simultaneously, do they access the cache concurrently?

GitLab Runner will restore and extract the cache in a CI/CD job.

When the job finishes, the cache gets saved again.

Example from build-latest (#5664790900) · Jobs · Developer Evangelism and Technical Marketing at GitLab / use-cases / CICD Components Catalog / Components (Templates) / Component - Rust Basic · GitLab

If jobs run concurrently, they might download the same cache, but later override the cache upload, depending which job finishes first. To prevent that, you can use resource_groups to lock the job, not being run in parallel. Resource group | GitLab

Alternatively, configure a cache key that is not global, but per branch. Caching in GitLab CI/CD | GitLab

2 Likes