variables:
- group: admin
- name: project
value: $[replace(lower($(Build.Repository.Name)), '.', '-')]
- name: DOCKER_REPOSITORY
value: foo.dkr.ecr.boo.amazonaws.com/$(project)
- name: Version
value: '1.0'
I couldn't make this replace/lower part work, what am I doing wrong? I tried 100 different combination
Build.Repository.Name : Foo.Boo.Hoo
(expected result) project : foo-boo-hoo
CodePudding user response:
Azure DevOps variable resolution can be very tricky. You're in the right neighborhood, but missing some important distinctions.
You're combining different variable expansion syntaxes in one expression.
$()
is macro syntax. Variables with macro syntax get processed before a task executes during runtime.$[]
is runtime syntax. Runtime expression syntax is expanded at runtime. Runtime expressions are designed to be used in the conditions of jobs, to support conditional execution of jobs, or whole stages.
[Ref: Microsoft Docs]
When you access a variable within an expression, you can use variables.variableName
. The exception is if the variable name itself has a .
in it, in which case you should use variables['variable.Name']
.
What you are actually looking for here is a compile-time expression: ${{ replace(lower(variables['Build.Repository.Name']), '.', '-') }}