如何在Azure Devops中查看预定义变量

cdmah0mi  于 2023-04-07  发布在  其他
关注(0)|答案(2)|浏览(139)

我想看到的值是预定义变量的路径,如$(System.DefaultWorkingDirectory),我想看到存储在其中的值。我无法找到此变量值,所以我可以在Azure devops中找到它。
简单地说,我如何检查在特定的发布管道中使用的Build.sourcesDirectory或Build.Repository.LocalPath是什么?

9ceoxa92

9ceoxa921#

我不确定你是否在Azure DevOps中找到了值背后的特定位置。值可能会有所不同,具体取决于你为代理选择的操作系统。但是,你总是可以将它们打印出来。请检查doc here

steps:
  - bash: echo $(System.DefaultWorkingDirectory)

要打印所有变量,您可以使用此步骤(因为变量也可以通过环境变量提供给脚本)

steps: # 'Steps' section is to be used inside 'job' section.
  - task: Bash@3
    inputs:
      targetType: 'inline'
      script: 'env | sort'

另一个适用于Windows和Linux的选项是(所有功劳都归功于Joe):

- pwsh: (gci  env:* | sort-object name)

您也可以使用第三方扩展Print all variables

- task: printAllVariables@1
    displayName: 'Print all variables via extension'

或类似的表达:

- ${{ each var in variables }}:
    - pwsh: Write-Host "${{ var.Key }} - ${{ var.Value }}"
      displayName: 'Print variables via expression in the loop'

下面是一个示例管道:

trigger: none
pr: none

name: Display pipeline variables

variables:
- group: DisplayPipelineVariables
- name: DB_HOSTNAME
  value: 10.123.56.222
- name: DB_PORTNUMBER
  value: 1521
- name: USERNAME
  value: TEST
- name: PASSWORD
  value: TEST
- name: SCHEMANAME
  value: SCHEMA  
- name: ACTIVEMQNAME
  value: 10.123.56.223
- name: ACTIVEMQPORT
  value: 8161

pool:
  vmImage: $(imageName)

jobs:
- job: AllEnvironmentVariables
  strategy:
    matrix:
      linux:
        imageName: 'ubuntu-latest'
      mac:
        imageName: 'macOS-latest'
      windows:
        imageName: 'windows-latest'
  steps:
  - script: env | sort
    displayName: Display all environment variables

- job: PipelineVariablesViaExtension
  strategy:
    matrix:
      linux:
        imageName: 'ubuntu-latest'
      mac:
        imageName: 'macOS-latest'
      windows:
        imageName: 'windows-latest'
  steps:
  - task: printAllVariables@1
    displayName: 'Print all variables via extension'

- job: PipelineVariablesViaExpression
  strategy:
    matrix:
      linux:
        imageName: 'ubuntu-latest'
      mac:
        imageName: 'macOS-latest'
      windows:
        imageName: 'windows-latest'
  steps:
  - pwsh: Write-Host "${{ convertToJson(variables) }}"
    displayName: 'Print all variables via expression'

- job: PipelineVariablesViaExpressionInLoop
  strategy:
    matrix:
      linux:
        imageName: 'ubuntu-latest'
      mac:
        imageName: 'macOS-latest'
      windows:
        imageName: 'windows-latest'
  steps:
  - ${{ each var in variables }}:
    - pwsh: Write-Host "${{ var.Key }} - ${{ var.Value }}"
      displayName: 'Print variables via expression in the loop'
xlpyo6sf

xlpyo6sf2#

更简单的答案:

- bash: |
      env | sort
    displayName: 'Debug: Show Env Vars'

相关问题