Is is possible to invalidate or clear a pipeline cache with Gitlab CI after a pipeline completes?
My .gitlab-ci.yml
file has the following global cache definition
cache:
key: "%CI_PIPELINE_ID%"
paths:
- './msvc/Project1`/bin/Debug'
- './msvc/Project2`/bin/Debug'
- './msvc/Project3`/bin/Debug'
The cache-key
value specifies that each pipeline should maintain it's own cache, which is working fine, but the cache file continues to exist after the pipeline completes. With hundreds of pipelines being run, the size starts to add up and manually deleting the cache folder on our machine isn't a great solution.
I tried adding a cleanup job at the end of the pipeline
cleanup:
stage: cleanup
script:
- rm -rf './msvc/Project1/bin'
- rm -rf './msvc/Project2/bin'
- rm -rf './msvc/Project3/bin'
when: always
which deletes the local files, but won't delete them from the cache.
Am I missing something here?
Currently running Gitlab-EE 10.3.3
The location also depends on the type of executor. Locally, under the gitlab-runner user's home directory: /home/gitlab-runner/cache/<user>/<project>/<cache-key>/cache. zip . Locally, under Docker volumes: /var/lib/docker/volumes/<volume-id>/_data/<user>/<project>/<cache-key>/cache.
Cache is stored where GitLab Runner is installed and uploaded to S3 if distributed cache is enabled. Use artifacts to pass intermediate build results between stages. Artifacts are generated by a job, stored in GitLab, and can be downloaded.
It's not a perfect solution, but we ended up creating a cleanup job at the end of our .gitlab-ci.yaml
file that deletes the cache directory from the filesystem.
This way, each pipeline gets its own unique cache, without cluttering up the file system over time.
cleanup_job:
stage: cleanup
script:
- echo "Cleaning up"
- rm -rf "%CACHE_PATH%/%CI_PIPELINE_ID%"
when: always
where
CACHE_PATH: "C:/gitlab-runner/cache/group/project/repo/"
Artifacts are the solution as mentioned in the comments. However there is an option to clear caches in the Pipelines page as shown in the image below.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With