I am trying to make my environment variables dependent on the Agent operating system.
I wrote the following test.yml, but it does not work:
jobs:
- job: Test
pool:
vmImage: 'ubuntu-latest'
steps:
- pwsh: |
echo $env:TestVar
echo $env:OS
env:
OS: $[variables['Agent.OS']]
${{ if eq(variables['Agent.OS'], 'Windows_NT') }}:
TestVar: "I am Windows"
${{ if eq(variables['Agent.OS'], 'Linux') }}:
TestVar: "I am Linux"
Is there a problem with my YAML indentation?
OSenvironment variable, you should be able to accessAgent.OSdirectly as$env:Agent_OS.envTestVaris empty. Also, OS is just printed as$[variables['Agent.OS']]. I can fix that by using$(Agent.OS), but that is another issue.OS: $(Agent.OS). If you change${{ if eq(variables['Agent.OS'], 'Windows_NT') }}to${{ if eq(variables['Build.SourceBranchName'], 'master') }}, theTestVarcan be printed. It seems agent variable is not supported in such scenario.