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

How does bitbucket pipelines cache work

Filip Baszak December 18, 2023

Im a bit confused about bitbucket pipelines cache.

Im using predefined cache:

caches:

  - maven: .m2

And each time when I run maven command and I use defined cache, bitbucket says that it is importing cache and extracting it, but pipelines step still fetches dependency from web.

Why does it happen?

1 answer

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 19, 2023

Hello @Filip Baszak and thank you for reaching out to Community!

When using a pre-defined cache, you don't need to specify the folder to cache, as Bitbucket Pipelines will get them from the default location used by that framework/took. For Maven, you should define the cache as follows: 

caches: 
- maven

This would cache dependencies that maven saves in the directory ~/.m2/repository. You can check other available pre-defined caches and their respective directories in our Cache Dependencies documentation.

The way that cache works is that the first time you run the build after adding the cache to your YML, the dependencies will be downloaded from the internet, and at the end of the step, all dependencies in the cache directory will be compressed and saved by Bitbucket. In the subsequent builds, at the start of the step bitbucket will download the previously generated cache and extract it to the same directory they were originally generated. The cache lasts for 7 days. After that period, the following build will again download the dependencies from the internet, which will generate a new cache that will last another 7 days, and so on.

You can find more details and learn more about limitations of caches in the following documentation : 

Should you have any questions, feel free to ask!

Thank you, @Filip Baszak !

Patrik S

Suggest an answer

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

Atlassian Community Events