Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure pipelines template - toLower on a parameter

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 🥴.

like image 573
qwertoyo Avatar asked Dec 14 '22 10:12

qwertoyo


2 Answers

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

Example

parameters:
- name: someString
  type: string
  default: "HELLO"    

variables:
   A: ${{ lower(parameters.someString) }}

steps:
  - script: echo $A # outputs hello
like image 124
JoshuaTheMiller Avatar answered Dec 15 '22 23:12

JoshuaTheMiller


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
like image 26
4c74356b41 Avatar answered Dec 15 '22 22:12

4c74356b41