Clearing build cache

Hello, I’m looking into automating clearing the build cache from a workflow instead of going in the settings and manually deleting the cache.

I tried creating a workflow that would only do a “cache-push” step and nothing else. But that didn’t seem to clear it.

Anyone know of another way?

Hello @MarcGrenierIntact :wave:

Currently there is no step or any other automatized option to delete your cache, though they do get automatically deleted after 7 days if unused.
Could you give a bit more detail as to why you would need this feature? You can also have workflows that simply don’t include the Cache:Pull step (and this not use cache), or you can give a condition to the step to only run in certain conditions: Enabling or disabling a Step conditionally | Bitrise DevCenter

Hi @Roland-Bak :wave:

Thanks for the feedback! My team needs this feature because we support multiple internal libraries that in one of our project are updated pretty frequently (multiple times a day). This causes our cache to grow in size pretty rapidly. From less than 2 GB on the first cache push to more than 8GB in 2 weeks. So doing a clean up once every week or two would ensure us that our cache is clean and takes a reasonable time to pull and push.

The good news is that I found an easy way to do this. Here are the steps in case anyone sees this post in the futur :

  1. Download your cache in “Settings > Manage Build caches” and check which paths are being cached.
  2. Create a new empty workflow
  3. Add a script step and a cache push step
  4. In the script step create the directories you would want to be cleaned from the cache. For me, it was the ~/.gradle directory. I also added a bit of logic to only run the script every 2 weeks.
  5. Add this path to the “Cache paths” of the cache push step.
  6. Schedule a build every week on the branch that has the cache.
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.