I have a build template used by several pipelines, and I need to simply transform a parameter using toLower.
toLower is documented here https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-functions-string#tolower
this is my last attempt:
parameters:
imageName: '$(Build.Repository.Name)'
lcImageName: "$[toLower(parameters.imageName)]" #this is my current attempt
later on, on a Bash@3 step, I'm trying to use the value with
args: 'omitted/${{ parameters.lcImageName }}:$(output.dockertag)'
but I can see the value is not expanded
I also tried to directly call that toLower where I needed it, no expansion neither.
I just need to transform a param using toLower and use it in a specific step, I'm a bit surprised I'm asking this here 🥴.
No need for any workarounds! There is a lower
function in Azure DevOps Pipelines (not toLower
):
lower
- Converts a string or variable value to all lowercase characters
- Min parameters: 1. Max parameters 1
- Returns the lowercase equivalent of a string
- Example: lower('FOO') returns foo
~from MS docs
parameters:
- name: someString
type: string
default: "HELLO"
variables:
A: ${{ lower(parameters.someString) }}
steps:
- script: echo $A # outputs hello
here's an example of doing what the existing answer suggests (I dont think there is any other way of doing this except for using a script):
- bash: |
${{ format('imageName=$(echo "{0}" | tr "[:upper:]" "[:lower:]")
echo "##vso[task.setvariable variable=imageName]$imageName"',
parameters.solutionName ) }}
displayName: Image Lowercase
EDIT:
this is now supported via lower()
command:
Example: lower('FOO') returns foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With