我正在尝试在Azure Pipeline YAML中缓存我的npm包。我使用的代码来自微软:https://docs.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#nodejsnpm
以下是我的YAML文件的一部分:
steps:
- task: NodeTool@0
displayName: 'Use Node 12.x'
inputs:
versionSpec: 12.18.3
checkLatest: false
- task: Npm@1
displayName: 'npm install'
inputs:
workingDir: WebApp
verbose: false
- task: Cache@2
inputs:
key: 'npm | "$(Agent.OS)" | package-lock.json'
restoreKeys: npm | "$(Agent.OS)"
path: $(npm_config_cache)
displayName: Cache NPM packages当我运行管道时,它会失败,并显示以下消息:
A task is missing. The pipeline references a task called 'Cache'. This usually indicates the task isn't installed, and you may be able to install it from the Marketplace: https://marketplace.visualstudio.com. 我尝试从Microsoft Marketplace安装缓存任务,但该任务不可用。我使用的是Azure DevOps Server2019和6月的更新。缓存任务还没有被弃用,根据这个页面:https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/cache?view=azure-devops,它应该可以与我的Azure DevOps服务器版本一起工作。如何安装缓存任务?
更新:
我在一个微软开发者论坛上找到了一篇关于同样问题的帖子:https://developercommunity.visualstudio.com/content/problem/1092245/cache-task-not-available-on-azure-devops-server.html。显然,缓存任务目前在Azure DevOps Server2019上不可用。我得找个变通的办法。说起来很可笑。微软没有提供缓存任务,也没有在他们的网站上发布任何关于它的内容。
发布于 2020-09-03 15:14:47
如果您使用的是自托管代理。您可以在管道中添加checkout步骤,并将clean属性设置为false(如果未指定,则默认为true )。这样就不会在下次生成时清除源文件夹中已安装的依赖项。这将加快npm安装任务的速度。如下所示:
steps:
- checkout: self
clean: false
- task: NodeTool@0
displayName: 'Use Node 12.x'
inputs:
versionSpec: 12.18.3
checkLatest: false
- task: Npm@1
displayName: 'npm install'
inputs:
workingDir: WebApp
verbose: false有关更多信息,请查看here。
https://stackoverflow.com/questions/63705723
复制相似问题