bomtom
bomtom

Reputation: 109

Azure Devops: Is it possible to use a variable template with variable group inside a job template?

I tried to use a variable template containing a variable group in a template with some steps. This is included into a pipeline. Azure tells me that there is "Unexpected value 'variables'" in the template using the variable template.

I tried to make it possible with following code

templates/VariableGroupTemplate.yml:

- variables:
  - group: MyVariableGroup

templates/ReferingVariableGroupTemplate.yml:


parameters:

- name: Folder
  default: "c:/temp"

variables:

- template: VariableGroupTemplate.yml

steps:

- task: Powershell@2
  inputs: Write-Host "Variable from group: $VariableFromGroup -- Folder: ${{ parameters.Folder }}"

The Azure Pipeline tells me that variable in templates/ReferingVariableGroupTemplate.yml does not work.

I used this documentation as a guide: https://learn.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups?view=azure-devops&tabs=yaml

Upvotes: 0

Views: 338

Answers (1)

fenrir
fenrir

Reputation: 383

The documentation you used tells how to use variable group use variable group

If you follow it then it will work.

templates/VariableGroupTemplate.yml:

variables:
- group: MyVariableGroup

templates/ReferingVariableGroupTemplate.yml:

parameters:
- name: Folder
  default: "c:/temp"

variables:
- template: VariableGroupTemplate.yml

steps:
- script: echo $(VariableFromGroup)

Upvotes: 1

Related Questions