user12413265
user12413265

Reputation: 103

Multiple Variable Groups in Azure Devops YAML pipelines

Using the Azure Devops gui, it is very easy to scope variable groups to pipeline stages. I need to replicate this functionality in a yaml build/release pipeline but I cannot find a way to do it. Anyone found a way to do this yet?

Upvotes: 10

Views: 13214

Answers (3)

reim
reim

Reputation: 612

parameters:
- name: stage
  displayName: Stage
  type: string
  default: Development
  values:
  - Development
  - Staging
  - NonProd

variables:
    serviceConnection: 'Your-Favourite-SC'

stages:
- stage: Deploy_Resources
  displayName: Deploy Resources
  variables:
    - group: "Somevargroupname - Release" 
    - group: "Somevargroupname - ${{ parameters.stage }}" 

Quick and simple!

Upvotes: 7

Mengdi Liang
Mengdi Liang

Reputation: 18958

Scope variable groups to pipeline stages functionality in a yaml build/release pipeline

With YAML, the way to achieve that is just specify the Variable group at the stage level to let it available only to this specific stage.

For example, I have a variable group names 1122. And 2 stages: one and two. Now, I want this variable group only available for stage one, which means the stage two should not access its content.

See below simple sample:

stages:
- stage: one
  displayName: one
  variables:
  - group: 1122

  jobs:
  - job: A
    steps:
      - bash: echo $(a)


- stage: two
  displayName: two

  jobs:
  - job: A1
    steps:
      - bash: echo $(a)

enter image description here

Upvotes: 9

Related Questions