Reputation: 9806
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?
Upvotes: 4
Views: 8338
Reputation: 89
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')
Upvotes: 1
Reputation: 146
One more thing - In order that cache task works as expected all task must succeed.
Upvotes: 2
Reputation: 31063
Set variable system.debug
to true
to get more information.
You would check the path to see whether it is correct on the agent machine (you are using self-hosted agent, correct?)
Usually, on the first run after the task is added, the cache step will report a "cache miss" since the cache identified by this key does not exist. As you always got "cache miss" issue, I suspect the cache is not created or uploaded correctly. You may try to do some modification for package-lock.json
to recache and re-generated one new key, to see how's the result.
Upvotes: 0