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

Azure Cache@2任务文件匹配模式不符合预期问题咨询

问题原因及解决办法

核心原因

Azure DevOps的Cache@2任务在处理key中的文件路径匹配时,默认基于当前工作目录($(System.DefaultWorkingDirectory))进行glob查找,而非直接解析绝对路径。你使用的$(Agent.BuildDirectory)/s/*/pom.xml是绝对路径,任务会在工作目录下尝试寻找这个完整绝对路径对应的文件,自然匹配不到实际存在的$(Agent.BuildDirectory)/s/子目录/pom.xml。

解决办法

调整为相对路径

由于$(Agent.BuildDirectory)/s通常等价于$(System.DefaultWorkingDirectory)(Azure DevOps默认将代码拉取到这个路径),你可以直接使用相对路径来匹配一级子目录的pom.xml:

- task: Cache@2
  inputs:
    key: 'maven | "$(Agent.OS)" | */pom.xml'
    path: $(MAVEN_CACHE_FOLDER)
  displayName: Cache Maven local repo

如果s是工作目录下的子文件夹(而非工作目录本身),则调整为:

- task: Cache@2
  inputs:
    key: 'maven | "$(Agent.OS)" | s/*/pom.xml'
    path: $(MAVEN_CACHE_FOLDER)
  displayName: Cache Maven local repo

验证路径匹配

可以先添加一个命令行任务,确认路径匹配是否正确:

- task: CmdLine@2
  inputs:
    script: |
      # 验证一级子目录的pom.xml是否存在
      find $(System.DefaultWorkingDirectory) -maxdepth 2 -name "pom.xml"
  displayName: Verify pom.xml paths

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 10:23:12