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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.