Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Merge cache from multiple steps

Ian Liu Rodrigues January 4, 2024

If I have two consecutive steps using the same cache, for example, `pip`. Will the caches be merged? Is it possible to merge the same cache from multiple steps?

1 answer

0 votes
Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 7, 2024

G'day, @Ian Liu Rodrigues 

I believe merging the same cache from multiple steps is impossible as the cache is created when steps succeed. However, you might want to look into the Smart caches that we just released last year:

Announcing smarter caches in Bitbucket Pipelines 

Cache keys provide a way to uniquely identify versions of a cache based on a set of files in your repository. The typical use case would be to define a cache key based on files that define a project's dependencies. When dependencies are updated, the hash of the key files also updates and Pipelines will be able to generate a unique cache version for subsequent builds. As multiple cache versions are able to be retained, future builds using either the old or new dependency set will have a unique cache version to reuse.

I hope this helps.

Regards,
Syahrul

Ian Liu Rodrigues January 11, 2024

Hi @Syahrul , thanks for the reply!

I've read the documentation page you've linked, and I think it wouldn't solve this issue.

I guess the best term here isn't "merging caches", but a "global cache", that is updated on every step if the contents of the cache directory changes between steps.

For example, consider the following scenario:

Step 1 only installs linting tools, so the pipeline fails as fast as possible in case of a lint error, and caches the pip packages to speedup even further.

Step 2 installs build dependencies, which also caches in the pip cache, but this will not work because now the cache only contains the linting tools. I think Smart caches can't solve this either, since my requirements.txt file didn't change here.

I guess I could define multiple caches for each step, but this gets really cumbersome, and the same packages would be cached multiple times.

To overcome this difficulty, all my bitbucket pipelines are now a single step.

Like Syahrul likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events