I have a step where I check if there are changes in a specific folder since the last commit (I set isOutput=true because I need this in another stage later as well):
bash: |
git checkout origin/$(System.PullRequest.SourceBranch)
DIFF_VALUE=$(git diff --name-only HEAD..HEAD~1 -- functions/$(directoryName) | wc -l)
echo Looking for changes in directory: $(directoryName)
if [[ $DIFF_VALUE -eq 0 ]]
then
echo "There are no changes since the previous commit."
echo "##vso[task.setvariable variable=gitDiff;isOutput=true]false"
else
echo "There are changes since the previous commit."
echo "##vso[task.setvariable variable=gitDiff;isOutput=true]true"
fi
name: check_changes
displayName: Check Changes
Now I want to include some steps that are in file called function.yml, but I only want them to run if there were no changes in that folder since the last commit! Since it is not possible to add condition to a template step, I add the template step with the parameter gitdiffbool (which is actually a string, but that is okay):
- template: ../steps/ci/function.yml
parameters:
directoryName: $(directoryName)
gitdiffbool: $(check_changes.gitDiff)
My function.yml looks like this:
parameters:
- name: directoryName
type: string
- name: gitdiffbool
type: string
steps:
- bash: echo "Diff value is ${{ parameters.gitdiffbool }}!"
- ${{ if eq(parameters.gitdiffbool, 'true') }}:
- bash: echo "This step and others after this never run!!!!"
When I run this, the first bash inside the function.yml will always run and display the parameter value correctly:
Diff value is false! or Diff value is true! according to if I had changes in that particular directory or not. But it can't resolve the same parameter inside the ${{ if ... }}
.
No matter how I try, it is never able to compare that if it is 'true' or 'false'. (I tried true, false, True, False, 'True', 'False', but no luck)
Why is it able to resolve ${{ parameters.gitdiffbool }}
correctly, but not the one ${{ if eq(parameters.gitdiffbool, 'true') }}
?
If things inside ${{ }}
get resolved during compile time, then why is the first bash able to output the correct string? What am I missing here?
How can I solve this without needing to add condition to all the tasks in the function.yml file?