Reputation: 386
I want include a template depending on the variable Agent.OS:
...
steps:
- ${{ if eq(variables['Agent.OS'], 'Linux') }}:
- template: /templates/prepare-tool.yaml
But this does not work. I don't see this step on the list of steps. I tried also:
- ${{ if eq(variables.AGENT_OS, 'Linux') }}:
The same result.
Maybe I'm wrong, but:
The difference between runtime and compile time expression syntaxes is primarily what context is available. In a compile-time expression (${{ }}), you have access to parameters and statically defined variables. In a runtime expression ($[ ]), you have access to more variables but no parameters.
So, I have to use - $[ if eq(...
for this variable, which is not static, but it does not work either:
Unexpected value '$[ if eq(variables.
I don't have idea how to use this kind of variable.
From what I found on stackoverflow(eg. 1, 2) this is impossible.
Upvotes: 4
Views: 2071
Reputation: 76880
Condition for template, using Agent.OS | AGENT_OS
Yes, you are right. There is no out of box way to do this.
Since the value of the variable Agent.OS
is a runtime variable, we could not use it before we run the job.
And the variable ${{ if eq(variables['Agent.OS'], 'Linux') }}
is a compile-time variable. So, Therefore, the judgment result of the condition is always a failure.
To resolve this issue, you could add the condition to the template for each step, like:
steps:
- script: echo Sometimes this happens!
condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))
Upvotes: 7