azure - 如何查看 Azure Devops 中的预定义变量

标签 azure azure-devops azure-pipelines azure-devops-self-hosted-agent azure-pipelines-tasks

我想查看预定义变量路径的值,例如 $(System.DefaultWorkingDirectory) 我想查看其中存储的值。 我无法找到这个变量值,那么我在 Azure DevOps 中哪里可以找到它。

简单地说,我如何检查该特定发布管道中使用的 Build.SourcesDirectory 或 Build.Repository.LocalPath 是什么?

最佳答案

我不确定您是否在 Azure DevOps 中找到了某个特定位置背后的值(value)观。根据您为代理选择的操作系统,值可能会略有不同。但是您始终可以将它们打印出来。请查看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'

enter image description here

适用于 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'

关于azure - 如何查看 Azure Devops 中的预定义变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61135431/

相关文章:

java - Azure 上的 Spring 和 Azure Spring Cloud 之间的区别

build - 如何对 msbuild 内置目标(如构建/重建)设置条件?

java - 在哪里为 Bitbucket 上托管的 Maven 项目上的 Azure DevOps 管道设置 Nexus 凭据?

azure-devops - 在 Azure Devops CI 中执行下载的管道工件时出现权限问题

azure - 什么是 Docker 注册表服务连接?

c# - azure 函数中的 HTTP 补丁

azure - 在 Azure 数据工厂中形成 SFTP 连接 - 无法协商 key 交换算法

azure - Azure DevOps 管道中的条件阶段执行

azure-devops - 在 Azure DevOps Wiki 中添加图像

azure - Get-AzRecoveryServicesVault 在 devops 发布管道中抛出 "Could not load file or assembly Microsoft.Azure.PowerShell.Authentication"