android - NPM 缓存步骤在 Azure DevOps 中不起作用
问题描述
我按照 Microsoft 的以下文档为我尝试在 azure 中构建的 android 应用程序配置 npm 缓存步骤,而不是 package.json-Lock 我使用的是 package.json。
https://docs.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#nodejsnpm
我能够在缓存后步骤中上传缓存依赖文件,并在第二次运行管道时正确上传该文件,但即使在工作区中下载了 npm 缓存数据后,npm install 步骤仍在调用远程库和下载远程依赖项。
我还尝试为 npm install 步骤运行npm install --prefer-offline但确实有效。如果我还缺少任何东西,请告诉我。
谢谢你。
解决方案
使用该Cache
任务缓存应用程序的 node_modules 文件夹。使用缓存命中变量 ( cacheHitVar
) 来存储缓存恢复的结果。true
缓存恢复时(缓存命中)将设置为 ,否则设置为false
。
然后为安装依赖项的任务使用条件(例如npm ci
)。仅在缓存未命中时安装它们。
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')
成功恢复缓存后,您将在管道执行中看到以下输出。
推荐阅读
- android - 未定义对“ASurfaceTexture_fromSurfaceTexture”的引用
- sql - Postgres Where 查询不适用于字符变化数据类型的数值
- vb.net - 无法在某些项目的组合框中设置默认项
- powershell - 底层连接已关闭:发送时出现意外错误
- css - 如何在材质 ui 上使用过渡使模态居中并使其响应?
- excel - 将一列的参考编号复制到另一列
- php - 如何将adwords代码放入php的ajax查询方法中?
- arrays - node.js 在间隔中迭代数组特定时间
- arrays - 根据多个数组值过滤文件行
- javascript - 即使它不在 console.log (...) 中,值为 null