【发布时间】:2020-04-16 15:33:08
【问题描述】:
我正在尝试在管道中缓存 npm 依赖项,下面是 yaml 代码
jobs:
- job: Cypress_e2e_tests
pool:
vmImage: 'windows-latest'
variables:
npm_config_cache: C:\Users\VssAdministrator\AppData\Local\npm-cache
steps:
- task: NodeTool@0
inputs:
versionSpec: '10.x'
- task: CacheBeta@1
inputs:
key: npm | $(Agent.OS) | package-lock.json
path: $(npm_config_cache)
restoreKeys: npm | $(Agent.OS) | package-lock.json
displayName: Cache NPM packages
- task: CacheBeta@1
inputs:
key: 'cypress | $(Agent.OS) | package-lock.json'
path: 'C:\Users\VssAdministrator\AppData\Local\Cypress'
restoreKeys: 'cypress | $(Agent.OS) | package-lock.json'
displayName: Cache cypress binary
- script: npm cache verify
displayName: 'NPM verify'
- script: npm ci
displayName: 'Install NPM dependencies'
- script: npm run cy:verify
displayName: 'Cypress verify'
- script: |
npx cypress run --browser chrome
displayName: 'Run Cypress tests'
workingDirectory: $(System.DefaultWorkingDirectory)
- task: PublishPipelineArtifact@0
displayName: 'Publish Screenshots (Cypress)'
condition: failed()
inputs:
artifactName: 'screenshots'
targetPath: '$(Build.SourcesDirectory)/cypress/screenshots'
- task: PublishPipelineArtifact@0
displayName: 'Publish Videos (Cypress)'
condition: failed()
inputs:
artifactName: 'videos'
targetPath: '$(Build.SourcesDirectory)/cypress/videos'
- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '*.xml'
failTaskOnFailedTests: true
testRunTitle: 'Cypress Test Results'
publishRunAttachments: true
condition: succeededOrFailed()
但是在第二次运行中,我得到了以下信息,并且缓存似乎没有按预期工作,
信息,缓存未命中。
【问题讨论】:
-
这 2 个构建是否建立在 2 个不同的分支上?还是同一个分支?对我来说,如果它基于同一个分支,一切都很好。你能更新完整的缓存日志吗?
-
是的,这是针对同一个分支的。你认为我们可以在 YAML 中指向窗口的 AppData 而不使用上面的硬编码值吗?
-
不。如果您用绝对值对其进行硬编码,那一切都很好。但我更建议您使用动态值。你比较了这两个版本的关键值吗?它们是一样的吗?
-
只是想在周末后检查一下这个问题的状态是什么?下面的解释能解决你的困惑吗?
-
现在似乎工作正常。但在这两者之间,我看到两次运行使用相同的指纹,但仍然显示缓存未命中。但我今天检查了一下,它现在正在工作并恢复缓存文件,而不是从头开始下载所有内容。感谢您的回答,如果我再次遇到相同的情况,即恢复操作显示缓存未命中,即使它们使用相同的指纹,我也会回复您。
标签: npm azure-devops azure-pipelines cypress npm-cache