Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to invalidate build cache on a given branch?

I'm using Gitlab CI on one of my projects and I face the following problem :

  • My master build fails since a lot of time...
  • I push a new branch built from the master (no new commits) and push it, the build works.

I think that it's related to build cache because the codebase is strictly the same... The latest valid build cache may make the current code base failed...

Is there a way to clean the build cache on a specific branch ? In my case the master ? From the API ?

like image 962
shulard Avatar asked Feb 17 '17 15:02

shulard


1 Answers

Finally, the Gitlab Team gave me the solution on Twitter : https://twitter.com/gitlab/status/832674380790394880

Since my repository is hosted on gitlab.com, I can't remove the cache by myself. But on the .gitlab-ci.yml file documentation, it's explained that we can use a cache:key entry.

This cache:key is used to determine how the cache entry is named so I can change the default value to start on a blank cache 😊.

Below a sample of my .gitlab-ci.yml file :

my-asset-build:
  cache:
    key: "$CI_COMMIT_REF_NAME-assets"

With that configuration, my cache is related to the current ref (so a build on the same ref will use the cache) with a suffix !

Thanks to the Gitlab Team for their quick answer on Twitter !

If you have trouble with the variable name, maybe you need to check this page : https://docs.gitlab.com/ce/ci/variables/README.html#9-0-renaming

Also, since Gitlab 10.4, we have a "Clear runner cache" button in the pipeline list. Clicking on that button will have the same effect than changing variable name without polluting commit history.

like image 71
shulard Avatar answered Nov 15 '22 08:11

shulard