天青管道-打印变量以输出

时间:2020-02-05 11:16:35

标签: azure-pipelines

我正在为这个简单的任务而苦苦挣扎:

variables:
  myVariable: 'ValueFromVar'

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: ${myVariable} # prints empty

- task: PowerShell@2
  displayName: Display version of app
  inputs:
    targetType: 'inline'
    script: 'Write-Host "Version of app: ${myVariable}"' # prints empty

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: echo '${myVariable}' # prints ${myVariable} 

在azure管道中如何打印变量以输出的正确方法是什么?

1 个答案:

答案 0 :(得分:2)

关于如何使用自定义变量,请检查文档集variables in pipeline

在您的情况下,当您要使用变量时,它应该是$(myVariable)而不是${myVariable}

请参考以下演示:

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  myVariable: 'ValueFromVar'

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: '"$(myVariable)"'

- task: PowerShell@2
  displayName: Display version of app
  inputs:
    targetType: 'inline'
    script: 'Write-Host "Version of app: $(myVariable)"' 

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: echo '$(myVariable)'

enter image description here