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

Azure DevOps部署YAML管道中无法找到Bash脚本文件

问题原因

部署作业(deployment类型)和普通作业(job类型)的代码拉取逻辑不同:

  • 普通作业默认会自动克隆仓库代码到代理机器,因此能正常找到bash_scripts目录
  • 部署作业默认不会执行仓库克隆操作,这就是脚本文件找不到的核心原因
解决方案

有两种常用方法可以解决这个问题:

方法1:在部署作业中显式拉取代码

在部署作业的deploy步骤里添加Checkout任务,主动拉取当前仓库代码:

strategy:
  runOnce:
    deploy:
      steps:
      - checkout: self  # 拉取当前仓库代码
        fetchDepth: 1   # 可选:仅拉取最新提交,提升执行速度
      - task: Bash@3
        displayName: 'Get Image With Tag'
        name: GetImageWithTag
        inputs:
          targetType: 'filePath'
          filePath: 'bash_scripts/getImageToDeploy.sh'

方法2:从上游作业传递脚本文件

如果上游的普通作业(比如GetDockerImageTagsJob)已经能访问到脚本文件,可以通过发布/下载流水线工件的方式传递:

  1. 在上游作业末尾添加发布任务:
- task: PublishPipelineArtifact@1
  inputs:
    targetPath: 'bash_scripts'
    artifact: 'bash-scripts'
    publishLocation: 'Container'
  1. 在部署作业的步骤开头添加下载任务:
strategy:
  runOnce:
    deploy:
      steps:
      - task: DownloadPipelineArtifact@2
        inputs:
          artifact: 'bash-scripts'
          path: '$(Pipeline.Workspace)/bash_scripts'
      - task: Bash@3
        displayName: 'Get Image With Tag'
        name: GetImageWithTag
        inputs:
          targetType: 'filePath'
          filePath: '$(Pipeline.Workspace)/bash_scripts/getImageToDeploy.sh'
验证建议

调整配置后,可以再次运行tree $(System.DefaultWorkingDirectory)或tree $(Pipeline.Workspace)命令,确认bash_scripts目录是否已正常出现。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 20:12:04