Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to cache GitLab build artifacts only for a day?

I recently encountered a GitLab pipeline issue where my node_modules weren't being updated with newer versions of a library (particularly my own internal fork of a project, which uses the git+url syntax). I suspect, as the git+url doesn't have a version number in it, its tricky to hash the package file and detect there is a change...

My workaround was to try and put a $date entry in the cache entry of my .gitlab-ci.yml file, so that the cache is lost every 24 hours. However there is no CI variable listed which contains a date, and it doesn't seem that you can access OS variables everywhere in the yaml file. Is there a neat trick I can use?

I tried:

cache:
  key: "$(date +%F)" # or see: https://gitlab.msu.edu/help/ci/variables/README.md
  paths:
    - node_modules

before_script:
  - echo Gitlab job started $(date)

This doesn't seem to work - I think it just outputs the key string verbatum, although notice that the script echo command does.

Anyone have any neat ideas? For now, I am just putting a manual string, and will add a digit when I want to cause the cache to be blown (although it is a bit error prone)

like image 692
TimM Avatar asked Sep 12 '25 09:09

TimM


1 Answers

At this time there is no way to set the cache expiration time for CI jobs. If the cache is using too much disk space and you're using the Docker executor, you can explore a tool such as https://gitlab.com/gitlab-org/gitlab-runner-docker-cleanup which will keep X amount of disk space free on the runner at any given time by expiring older cache.

like image 120
Drew Blessing Avatar answered Sep 15 '25 19:09

Drew Blessing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!