'Consuming var group value in place of yaml template parameter

I have a yml file which calls a templated stage:

- template: pipeline-templates/iac/deploy-template.yml
  parameters:
    envName: dev
    varGroup: dev-variables-group-library

In the template I have made use of the template parameter:

parameters:
    envName: ''
    varGroup: ''

stages:
- stage: Deploy_for_${{ parameters.envName }}

I want to use the envName variable from the variable group, instead of the template parameters. I have tried template code like this:

parameters:
    envName: ''
    varGroup: ''

stages:
- stage: Deploy_for_$( envName )

When I do this, the pipeline throws an unrelated error, for example stating that the stage name cannot be duplicate. This is clearly because the variable envName is not being read.

There are other places in my template where the pipeline variable is read and used successfully, so what am I doing wrong in this particular part of the template script?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source