How to Cache Dependencies in Bitbucket Pipelines
The caches key restores a directory at the start of a step and saves it at the end, so unchanged dependencies are not re-downloaded.
Add caches: to a step. Use the predefined node cache, or declare a custom cache under definitions.caches pointing at any path.
Steps
- List
caches:on the step (for example- node). - For a custom path, add it under
definitions.caches. - Reference that custom cache name in the step
caches:list.
bitbucket-pipelines.yml
bitbucket-pipelines.yml
definitions:
caches:
pip: ~/.cache/pip
pipelines:
default:
- step:
image: python:3.12
caches:
- pip
script:
- pip install -r requirements.txt
- pytestGotchas
- A cache is keyed by its name and the step image; it is shared across branches, so do not cache build output you need fresh.
- Caches over 1 GB are not saved; trim the path or split it.
Related guides
How to Define a Basic Pipeline in Bitbucket PipelinesDefine a minimal Bitbucket Pipelines build by adding a bitbucket-pipelines.yml at the repo root with a defaul…
How to Pass Artifacts Between Steps in Bitbucket PipelinesPass build output between Bitbucket Pipelines steps with the artifacts key, which uploads matching paths and…