VivekDev
VivekDev

Reputation: 25389

Azure DevOps: How to pass on a variable to a template read from Library variable group

I have a variable group defined in pipeline > Library > variable group > called 'template-variable-group'

Defining Variable Group in Azure DevOps

All that I am trying to accomplish here is to pass on the value of the variable my-temp-var (in this case as you can see its value is my-template-value) to a template from the yaml file.

I have a yaml based pipeline as follows.

variables:
- group: template-variable-group

name: $(date:yyyyMMdd)$(rev:.r)

stages:
  - stage: Build

    jobs:
      - job: buildWebApp
        displayName: Build Release pipeline for Discount Service on Master branch

        steps:
        - script: |
            echo Here we go
          displayName: 'Command Line Script'

        - template: template.yaml
          parameters:
            variableToTemplate: ${{variables['my-temp-var']}}

And the template.yaml file is as follows.

parameters:
  variableToTemplate:

steps:

- task: CmdLine@2
  inputs:
    script: |
      echo Hello Hello Hello Hello Hello Hello
      echo ${{ parameters.variableToTemplate }}
  displayName: 'Run a two-line script'

I am not able to do that.

pipeline with a template

As you can see, that value is not reaching the template. What am I missing.

I saw this SO Answer but did not seem to be of help.

Upvotes: 1

Views: 2862

Answers (2)

Tapan
Tapan

Reputation: 53

Passing it this way $(my-temp-var) will only serve for printing the value somewhere. If you try to use it as a parameter to something say for an ssh connection, the passed value will not work. I am still exploring why but it does not wok.

Upvotes: 1

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41565

You can just pass it like a regular variable:

$(my-temp-var)

Upvotes: 1

Related Questions