I'm trying to cache the cypress installation in my build pipeline.
I have this task setup:
- task: Cache@2
inputs:
key: 'cypress | $(Agent.OS) | package-lock.json'
path: 'C:\npm\prefix\node_modules\cypress'
I've run the build pipeline multiple times but I'm always getting the same error:
There is a cache miss

This is the previous build:

As you can see it's the same fingerprint, so why is the caching not working?
One more thing - In order that cache task works as expected all task must succeed.

Check the "cache post-job task" results and see if the keys are different.
In my case I had to use npm install --no-save so that the package-lock.json file wasn't regenerated during the pipeline. This ensured the "cache post-job task" was using the same cache key when caching node_modules.
edit
Here is an exported example of what we currently use in our pipeline to cache npm modules.
(You must make sure that your package-lock.json is checked in to your code repository)
steps:
- task: Cache@2
displayName: 'Npm Install Cache'
inputs:
key: '"npm" | "$(Agent.OS)" | my-project/package-lock.json'
path: 'my-project/node_modules'
cacheHitVar: NpmInstallCached
- task: Npm@1
displayName: 'Npm Install'
inputs:
command: custom
workingDir: my-project/
verbose: false
customCommand: 'install --no-save'
condition: ne(variables['NpmInstallCached'], 'true')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With