I’m a bit new to azure pipelines and at moment I can’t solve this problem.
I have a variable stored in my azure pipeline which is: ENABLE_BUILD and the value is set to YES.
On my yaml file I have set my variables like this:
variables:
- group: my-var-group
- name: enableBuild
value: '$(ENABLE_IDB)'
- name: buildPath
${{ if eq(variables['enableBuild'], 'YES') }}:
value: 'path/build-file.jar*'
${{ else }}:
value: '.'
Now my question is: the enableBuild is getting the right value, which is ‘YES’.
But when I try to set the buildPath variable it always going to else statement, even if my ENABLE_IDB is filled with YES.
When I used echo, the enableBuild is getting the ‘YES’ value, and buildPath is getting ‘.’ value. Looking on internet I was not able to identify what is wrong with my if equals statement. I’m doing this validation in the correct way? Thanks.
2
Answers
This happens because of the compile vs runtime time variables, while here you’re referencing the
enableBuild
variable at compile-time, the value ofenableBuild
is fetched at runtime (since it tries to access an environment variable namedENABLE_IDB
).What are you trying to do exactly? Is this
ENABLE_IDB
supposed to be manually set?You could instead get it from a parameter:
And reference it like so:
According to Set variables in scripts, we can set a variable for future use with scripts.
The following is set an output variable for use in the same job. In this way, we can set the
buildPath
variable value based on theenableBuild
value.