I'm trying to insert an extra parameter in my pipeline based on a commit message fragment, running Azure DevOps Server 2020. I tried to implement it with the following code, without luck:
variables:
- name: commitMessage
value: $(Build.SourceVersionMessage)
steps:
- template: myTemplate.yaml
parameters:
${{ if contains(variables['commitMessage'], 'SPECIAL_MESSAGE') }}:
specialParam: 'someValue'
During investigation, I found that the expressions behave somewhat unexpected:
variables:
- name: commitMessage
value: $(Build.SourceVersionMessage)
steps:
- bash: |
echo "${{ variables['commitMessage'] }}"
echo "${{ contains(variables['commitMessage'], 'SPECIAL_MESSAGE') }}"
echo "${{ contains('test SPECIAL_MESSAGE', 'SPECIAL_MESSAGE') }}"
The script output is:
test SPECIAL_MESSAGE
False
True
The first line of the script outputs the commit message correctly. But the contains()
function in the second line of the script seems to be unable to process the variable, even though the commit message contains the SPECIAL_MESSAGE, the expression returns False
.
However, if I set my variable to a static string instead of the $(Build.SourceVersionMessage)
variable, the expression returns True
, and I am able to add the extra parameter:
variables:
- name: commitMessage
value: 'test SPECIAL_MESSAGE'
Any idea why the pipeline behaves like this, or how to make it work?