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

Azure DevOps多仓库checkout路径识别失败、PowerShell脚本无法执行问题

问题根因
  1. Azure DevOps多仓库检出场景下,若为checkout步骤显式指定path参数,仓库最终的检出路径是相对于$(Pipeline.Workspace)目录,而非默认的$(System.DefaultWorkingDirectory)(默认对应$(Pipeline.Workspace)/s)。你当前配置将rep1、rep2分别检出到$(Pipeline.Workspace)/test1和$(Pipeline.Workspace)/test2路径下,$(System.DefaultWorkingDirectory)目录为空,因此指定的脚本路径无法匹配到实际文件。
  2. 警告Module path not present as expected in hosted agent是由于任务无法找到指定的PowerShell脚本文件,连带依赖模块加载路径校验失败触发,并非托管代理缺失对应模块。
解决方案
  • 第一步:确认你的myPowershell.ps1存储在哪个仓库中,修改脚本路径为对应检出路径:
    • 脚本存储在rep1时,ScriptPath修改为 $(Pipeline.Workspace)/test1/folder1/myPowershell.ps1
    • 脚本存储在rep2时,ScriptPath修改为 $(Pipeline.Workspace)/test2/folder1/myPowershell.ps1
  • 第二步:可选添加调试步骤提前验证目录结构,避免路径配置错误:
- pwsh: |
    Get-ChildItem $(Pipeline.Workspace) -Recurse -Directory -Depth 3
  displayName: 打印工作空间目录结构
  • 第三步:如果仍存在模块路径警告,可为AzurePowerShell任务添加workingDirectory参数,指定为脚本所在仓库的检出根目录。
修正后完整配置示例(假设脚本存储在rep1中)
jobs:
- job: job1
  steps:
  - checkout: rep1
    path: test1
  - checkout: rep2
    path: test2

  # 可选调试步骤
  - pwsh: |
      Get-ChildItem $(Pipeline.Workspace) -Recurse -Directory -Depth 3
    displayName: 打印工作空间目录结构

  - task: AzurePowerShell@5
    inputs:
      azureSubscription: xxxxx
      ScriptType: 'FilePath'
      ScriptPath: '$(Pipeline.Workspace)/test1/folder1/myPowershell.ps1'
      workingDirectory: '$(Pipeline.Workspace)/test1'
      azurePowerShellVersion: 'LatestVersion'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 15:36:03