Skip to content
Latchkey

How to Cache Dependencies in Bitbucket Pipelines

The caches key restores a dependency directory at step start and saves it at the end.

Use the built-in node cache or define a custom cache by path, then list it under a step caches key so installs reuse the prior download.

Built-in and custom caches

Reference the built-in node cache, and define a custom cache for any other directory.

bitbucket-pipelines.yml
definitions:
  caches:
    npm: ~/.npm
pipelines:
  default:
    - step:
        name: Install and test
        caches:
          - node
          - npm
        script:
          - npm ci
          - npm test

Notes

  • The node cache is built in and targets node_modules; npm here is a custom cache for the download cache.
  • Caches are keyed by name and branch fallback; they are best-effort, not guaranteed hits.
  • Caches over 1 GB are dropped, so cache the download dir rather than huge build outputs.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →