The example (see sample-azure-pipeline.yml) uses the pwsh shortcut for the PowerShell task so it works across platforms.
In Step 1 the inline PowerShell script logic determines and sets the value of the IsFooBar variable.
It uses "logging commands" to set the variable.
Write-Host "##vso[task.setvariable variable=IsFooBar]$IsFooEqualToBar"See docs: Logging commands
Step 2 simply logs the value of the IsFooBar variable. Two techniques are used to access the value of the variable.
The first uses the YAML $(IsFooBar) syntax. The second uses the PowerShell syntax for access environment variable $env:IsFooBar.
Step 3 also only logs the value of the IsFooBar variable, but we put a condition on this step, the step is only run
if the value of the IsFooBar variable is true. The step's condition uses the YAML variables.IsFooBar
syntax to access the variable's value.
Step 4 is similar to Step 3, but the step is only run if the IsFooBar variable is not true.
Docs: Define variables
- Section: Set variables in scripts
Docs: Logging commands