Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue using node cache in pipeline yml

WadeW
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 17, 2019

Hello,

I am trying to use the node cache option for the first time, but I don't think I properly understand the setup. 

Here is what my yml looks like so far for testing:

 

image: node:dubnium

pipelines:

   branches:

      dev:

         - step:

               name: init

               caches:

               - node

               script:

               - npm install

         - step:

               name: build

              script:

              - npm run build

              artifacts:

              - public/**

 (ignore any tab/line break issues, the file parses fine, just me trying to format it in this post)

It was my understanding that this setup would do the following:
1) Check for node_modules, and if it doesn't exist, run step 1 to install them and then cache them. If it does exist, skip this step and just download the cache
2) Run the build step.

I can see the cache being created on the bitbucket UI, but every time I run this pipeline it runs the npm install (regardless of cache existing or not) and then fails on the build step as it can't find the node_modules. Do I need to format this differently? I know in the past, before trying to use cache, I would place the node_modules in the artifacts during the first step.

1 answer

0 votes
Steven Vaccarella
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 2, 2019

Hi Wade,

Pipelines never skips steps. Caches are just a way to pre-populate a directory within your step with files that were generated on a previous run of that step (or another similar step). I don't know a lot about npm, but I suspect you want to do something like the first example in the cache docs:

pipelines:
branches:
dev: - step: caches: - node  script: - npm install - npm run build
          artifacts:
            - public/**

The first time this step runs it will download all dependencies and populate the node cache. The second time it runs, the node cache will be unpacked into the node_modules directory before your step starts. The "npm install" command will still execute, but it should run much more quickly because all the dependencies are already downloaded.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events