Tiamo Idzenga
Tiamo Idzenga

Reputation: 1156

Why do my variable group variables have an empty value?

I set up a variable group called secret-variables and gave it access to my pipeline.

In my pipeline I use a variable template and inside that variable template I define the variable group. I pass the variables from the variable template to pipeline templates using template expression syntax.

azure-pipelines.yml:

trigger:
  - master

pool:
  vmImage: windows-latest

variables:
  - template: pipeline-variables.yml

stages:
  - template: templates/myPipelineTemplate.yml
    parameters:
      mySecretVariable: ${{ variables.mySecretVariable }}

pipeline-variables.yml:

variables:
  # secret-variables contain mySecretVariable
  - group: secret-variables
  - name: foo
    value: bar

Yet the value of mySecretVariable in myPipelineTemplate.yml is empty. What have I missed?

Upvotes: 2

Views: 1434

Answers (1)

Tiamo Idzenga
Tiamo Idzenga

Reputation: 1156

It seems that variable groups do not support template expression syntax. Macro syntax needs to be used in stead, change the code in the stage to:

stages:
  - template: templates/myPipelineTemplate.yml
    parameters:
      mySecretVariable: $(mySecretVariable)

This works because macro syntax is evaluated at runtime and template expression is evaluated at compile time.

Upvotes: 3

Related Questions