I'm trying to understand how to pass environment variables between Azure Pipeline tasks, jobs, and stages. I created a PowerShell task to define variable, according to the docs, but I can't seem to see them after my task completes. Here is a snippet that shows the stage that I create, with jobs and tasks. I'm trying to set the FOO variable in the 'PassVariable' task and then access it from the 'PowerShell' task.
Unfortunately, FOO is never passed. What am I doing wrong?
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: PowerShell@2
displayName: 'PowerShell Script'
name: PowerShellTask
env:
myVar: $FOO
inputs:
targetType: 'inline'
script: |
Write-Host "Foo: $FOO"