I followed the following doc from Microsoft to configure the npm cache step for android app i am trying to build in azure and instead of package.json-Lock i am using package.json.
https://docs.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#nodejsnpm
I am able to upload the cache dependency file in the post-cache step and upload that file in the beginning correctly when running the pipeline for 2nd time but even after the npm cache data is downloaded in the workspace the npm install step is still calling the remote libraries and downloading the remote dependencies.
I have also tried to run npm install --prefer-offline for the npm install step but did work. Please let me know if i am missing anything more.
Thankyou.
Use the Cache
task to cache your application's node_modules folder. Use the cache hit variable ( cacheHitVar
) to store the result of the cache restoration. It will be set to true
when the cache is restored (cache hit), otherwise set to false
.
Then use a condition for the task that installs your dependencies (eg npm ci
). Only install them on a cache miss.
steps:
- task: Cache@2
displayName: Cache node_modules
inputs:
key: 'npm | "$(Agent.OS)" | $(Build.SourcesDirectory)/package-lock.json'
path: $(Build.SourcesDirectory)/node_modules
cacheHitVar: CACHE_RESTORED
- task: Npm@1
displayName: 'Install the dependencies'
inputs:
command: custom
verbose: false
customCommand: 'ci'
condition: ne(variables.CACHE_RESTORED, 'true')
You'll see the following output in the pipeline execution when the cache was restored successfully.
This isn't much of an answer, because i have the exact same problem however this is my setup.
- task: Cache@2
displayName: Cache npm
inputs:
key: 'npm | "$(Agent.OS)" | $(Build.SourcesDirectory)/XX/package-lock.json'
restoreKeys: |
npm | "$(Agent.OS)"
path: $(npm_config_cache)
- task: Npm@1
displayName: Npm restore dependencies
inputs:
command: 'custom'
workingDir: '$(clientapps)'
customCommand: 'install --cache $(npm_config_cache)'
adding --cache
sets npm's cache file to a specific location. i'm now running a build with --prefer-offline and see if that helps. i'll answer here if that helps.
Please check the following official recommendation from Microsoft regarding node modules caching https://docs.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#nodejsnpm
variables:
npm_config_cache: $(Pipeline.Workspace)/.npm
steps:
- task: Cache@2
inputs:
key: 'npm | "$(Agent.OS)" | package-lock.json'
restoreKeys: |
npm | "$(Agent.OS)"
path: $(npm_config_cache)
displayName: Cache npm
- script: npm ci
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.