You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Azure Pipelines的Cache任务仅恢复或仅保存缓存?

Azure Pipelines Cache任务:仅恢复或仅保存的配置方法

Azure Pipelines的Cache@2任务没有直接的开关控制仅恢复/仅保存,但可以通过任务参数组合实现需求:

一、仅执行缓存恢复,不保存

通过设置saveCondition: false强制跳过缓存保存步骤,任务仅尝试恢复匹配的缓存:

- task: Cache@2
  inputs:
    key: 'npm | "$(Agent.OS)" | package-lock.json'  # 替换为你的缓存键规则
    restoreKeys: |
       npm | "$(Agent.OS)"  # 替换为你的恢复键规则
    path: $(npm_config_cache)  # 替换为你的缓存路径
  displayName: 'Restore Cache (No Save)'
  saveCondition: false

说明:saveCondition参数控制是否执行缓存保存,设置为false后,无论缓存是否命中,都不会触发保存操作。

二、仅执行缓存保存,不恢复

通过设置restoreCondition: false跳过缓存恢复步骤,任务直接执行缓存保存:

- task: Cache@2
  inputs:
    key: 'npm | "$(Agent.OS)" | package-lock.json'  # 替换为你的缓存键规则
    path: $(npm_config_cache)  # 替换为你的缓存路径
  displayName: 'Save Cache (No Restore)'
  restoreCondition: false

说明:restoreCondition参数控制是否执行缓存恢复,设置为false后,任务不会尝试恢复任何缓存,直接将指定路径的内容保存为新的缓存条目。

如果需要确保保存操作始终执行(即使缓存键已存在),可以额外添加saveCondition: always():

- task: Cache@2
  inputs:
    key: 'npm | "$(Agent.OS)" | package-lock.json'
    path: $(npm_config_cache)
  displayName: 'Force Save Cache (No Restore)'
  restoreCondition: false
  saveCondition: always()

内容的提问来源于stack exchange,提问作者Vandit Agarwal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 00:20:26