Setting up Bitbucket Pipelines with proper caching of NPM and Cypress

Ondřej Janošík
Aug 5, 2018 · 2 min read

Bitbucket Pipelines & Deployments is integrated CI/CD for Bitbucket Cloud that’s trivial to set up, automating your code from test to production (at least that’s what the official site says). However, setting up your pipelines with right commands and right caching in order to be as fast as possible requires some time. In this article, I am going to show how it can be done.


If you came here just to see the configuration without explanation here it is:



In this configuration, we are using the docker image node:10.8.0. If you want to use a different one, one can choose one from here.

Options section

This section is completely optional and you can skip this part. I am using this part to set the maximum length of the pipeline. Without this time to time something bad can happen and your pipeline can run forever.

Pipelines section

Pipelines section is the main section where you specify each step. We have two steps. In the first, we are installing packages, running tests and building the application. We are using NPM CI — new command in NPM that has been created especially for this use case (you can read more here). In the second step, we are running the E2E tests using Cypress. Cypress requires us to use a different image so we need to create a special step for that.

Cache definitions

Using a cache can help us to save a lot of build minutes. We are caching two folders — $HOME/.npm & $HOME/.cache/Cypress. The first one is boosting NPM CI command and the second one is holding the Cypress binary.


Bitbucket Pipelines is a great tool for CI/CD. This feature is paid based on the number of build minutes so I suggest you using NPM CI and have a look at the cache section in order to save your time and money :)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store