admin管理员组文章数量:1391995
In an Azure Devops YAML pipeline I'm passing in a parameter which contains all manner of things - double and single quotes, newlines, etc. It'll vary on each pipeline run.
Inside the template, I need to do a very simple equality check of that value against a specificx string, "valueX" like in the example below:
parameters:
- name: strValue
steps:
- task: Bash@3
displayName: 'Do stuff'
inputs:
targetType: inline
script: |
if [ "${{ parameters.strValue }}" == "valueX" ]; then
...
fi
But I can't hit on the right syntax. parameters.strValue
gets actually evaluated, so the entire string is output within the bash script, causing syntax errors when it contains certain characters. I was hoping to do a comparison using the var name as a reference instead.
I tried using heredoc syntax in the bash script to store the evaluated parameter value into a var, but that doesn't appear to work within the azure-YAML setting - it can never find the closing EOF. Perhaps there's a much simpler solution to this?
In an Azure Devops YAML pipeline I'm passing in a parameter which contains all manner of things - double and single quotes, newlines, etc. It'll vary on each pipeline run.
Inside the template, I need to do a very simple equality check of that value against a specificx string, "valueX" like in the example below:
parameters:
- name: strValue
steps:
- task: Bash@3
displayName: 'Do stuff'
inputs:
targetType: inline
script: |
if [ "${{ parameters.strValue }}" == "valueX" ]; then
...
fi
But I can't hit on the right syntax. parameters.strValue
gets actually evaluated, so the entire string is output within the bash script, causing syntax errors when it contains certain characters. I was hoping to do a comparison using the var name as a reference instead.
I tried using heredoc syntax in the bash script to store the evaluated parameter value into a var, but that doesn't appear to work within the azure-YAML setting - it can never find the closing EOF. Perhaps there's a much simpler solution to this?
Share Improve this question asked Mar 15 at 23:40 benjamin.keenbenjamin.keen 1,9862 gold badges20 silver badges29 bronze badges2 Answers
Reset to default 1This is a bash and interpolation parameter issue with with ADO pipelines. This should work using env to call the parameter
parameters:
- name: strValue
steps:
- task: Bash@3
displayName: 'Do stuff'
env:
PARAMETER: '${{ parameters.strValue }}'
inputs:
targetType: inline
script: |
if [ "$PARAMETER" == "valueX" ]; then
echo "Matching tested and confirmed"
fi
I tested this and I can confirmed it worked.
Ok, found a solution. It was to move the logic outside of the bash code.
parameters:
- name: strValue
steps:
- task: Bash@3
condition: ${{ eq(parameters.strValue, 'valueX') }}
displayName: 'Do stuff'
inputs:
targetType: inline
script: |
...
本文标签: Bash syntax for equality check of Azure template param containing any stringStack Overflow
版权声明:本文标题:Bash syntax for equality check of Azure template param containing any string - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744601191a2615075.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论