How to reference dynamically a variable template in an Azure Pipelines?

18 Views Asked by At

Trying to dynamically reference a variable template in Azure Pipelines, the following code fails:

# ./versions/v1.0.yml
variables:
  Foo: v2.0
  Bar: v1.6

# ./azure-pipelines.yml
variables:
- name: productVersion
  value: v1.0
- template: versions/$(productVersion).yml

steps:
- checkout: git://MyProject/MyRepo@refs/tags/$(Foo)

We receive the following error during validation:

/azure-pipelines.yml: File /versions/$(productVersion).yml not found in repository

I suspect that Azure Pipelines does not support this feature. Does someone have any info on this feature and some alternative yaml code to propose ?

1

There are 1 best solutions below

0
osim_ans On BEST ANSWER

You need to use the 'productVersion' variable via runtime expression syntax. Refer to this MS documentation for more information. https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#runtime-expression-syntax

./azure-pipelines.yml

variables:

- name: productVersion
  value: v1.0

- template: versions/${{ variables['productVersion'] }}.yml