You define the name in the power shell task, we need to print the variable via $($env:PASSVARIABLE_FOO)
or $(PassVariable.FOO)
instead of $FOO
. Check this doc
In addition, we can print the variables via bash cmd printenv and check the variables defined in the script
YAML sample
trigger: none
stages:
- stage: Test
displayName: Test
jobs:
- job: SetSemVer
displayName: 'Test Var Passing'
steps:
- task: PowerShell@2
displayName: 'Pass Variable'
name: PassVariable
inputs:
targetType: 'inline'
script: |
echo "##vso[task.setvariable variable=FOO;isOutput=true]Hello World"
- task: Bash@3
inputs:
targetType: 'inline'
script: 'printenv'
- task: PowerShell@2
displayName: 'PowerShell Script'
name: PowerShellTask
env:
myVar: $FOO
inputs:
targetType: 'inline'
script: |
Write-Host "Foo: $($env:PASSVARIABLE_FOO)"
Result:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…