I'm trying to use the build number of the pipeline in a conditional to determine which task to run.
Inspired by this example in the ADO expressions FAQ, I set a variable to the minor number of the build number:
- script: |
minor_run=$(echo $BUILD_BUILDNUMBER | cut -d '.' -f2)
echo "Minor run number: $minor_run"
echo "##vso[task.setvariable variable=minor]$minor_run"
This prints out the correct minor number, let's say Minor run number: 14 for the following examples.
If I want to print out the minor, I can do it like this
script: "echo $minor"
Now I want to use this in a conditional. I'm trying something like this:
- ${{ if eq(variables.minor, 14) }}:
- script: "echo first if worked"
- ${{ elseif eq(variables['minor'], 14) }}:
- script: "echo second if worked"
- ${{ else }}:
- script: "echo neither worked"
I always get to the else part. I have tried evaluating against '14' as well, but same result.
I have also tried evaluating $minor, $(minor), and just minor, but that causes the pipeline to fail entirely.
What's the correct way to use a defined variable in a conditional?