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

Azure Pipelines:查找对应路径的管道变量及变量输出方法

在Azure Pipelines中输出所有环境变量及路径问题解决

输出所有环境变量的方法

要查看运行时的全部Azure Pipelines环境变量,直接添加以下任务即可:

使用PowerShell任务(Windows代理)

- task: PowerShell@2
  displayName: 输出所有环境变量
  inputs:
    targetType: 'inline'
    script: |
      # 列出所有环境变量并格式化输出
      Get-ChildItem Env: | Format-Table -AutoSize

或者用更清晰的键值对形式输出:

- task: PowerShell@2
  displayName: 输出所有环境变量
  inputs:
    targetType: 'inline'
    script: |
      foreach ($envVar in Get-ChildItem Env:) {
          Write-Host "$($envVar.Name) = $($envVar.Value)"
      }

使用Bash任务(Linux/macOS代理)

如果你的构建代理是Linux或macOS系统,用Bash任务更合适:

- task: Bash@3
  displayName: 输出所有环境变量
  inputs:
    targetType: 'inline'
    script: 'printenv'

路径变量补充说明

你提到$(Build.SourcesDirectory)和$(Agent.BuildDirectory)指向C盘,这在微软托管的Windows代理上是默认行为(工作目录通常在C:\agent\_work路径下)。如果要确认代码checkout后的具体路径,可以在checkout任务后添加步骤验证:

- checkout: self
- task: PowerShell@2
  displayName: 验证路径信息
  inputs:
    targetType: 'inline'
    script: |
      Write-Host "当前工作目录: $(Get-Location)"
      Write-Host "源码目录: $(Build.SourcesDirectory)"
      Write-Host "代理构建目录: $(Agent.BuildDirectory)"

你的管道配置示例:

resources:
  repositories:
  - repository: self
    type: git
    ref: refs/heads/master
...
        steps:
        - checkout: self
...
        - task: PowerShell@2
          displayName: Display Build Dir
          inputs:
            targetType: 'inline'
            script: 'Write-Host "Build Directory Location: `"$(Agent.BuildDirectory)`""' 

        - task: NuGetCommand@2
          displayName: NuGet restore
          inputs:
            solution: '$(BuildParameters.solution)'
            selectOrConfig: config
            nugetConfigPath: '$(Agent.BuildDirectory)/src/tree0/nuget.config'

相关截图:
Azure Pipelines路径截图

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 00:26:08