azure-pipelines - 将变量打印到输出

Ala*_*bra 2 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} 

Run Code Online (Sandbox Code Playgroud)

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

Yan*_*SFT 5

关于如何使用自定义变量,请查看 doc Set 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)'
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明