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

Azure Pipeline在Windows服务器运行脚本失败:路径错误求助

问题排查与解决方案

核心问题

  1. 路径格式混用:脚本路径同时使用了正斜杠(/)和反斜杠(\),Windows代理解析混合路径时会出现识别错误,导致找不到目标文件。
  2. 任务类型不匹配:ShellScript@2 任务为类Unix系统(Linux/macOS)设计,在Windows服务器上运行.bat批处理脚本并不适配。

具体修复方案

方案1:用Windows原生Cmd任务运行批处理脚本

直接使用CmdLine@2任务,配合纯Windows格式的路径:

- task: CmdLine@2
  inputs:
    script: '$(Agent.BuildDirectory)\myFolder\project\script.bat'

方案2:通过Bash任务调用Windows批处理脚本

如果必须使用Bash@3任务,需通过cmd /c命令启动批处理脚本,同时统一路径为正斜杠格式:

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: |
      cmd /c "$(Agent.BuildDirectory)/myFolder/project/script.bat"

额外验证步骤

可添加打印变量的任务,确认$(Agent.BuildDirectory)在Windows代理上的实际路径:

- task: CmdLine@2
  inputs:
    script: 'echo $(Agent.BuildDirectory)'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 21:04:51