Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Devops: How to set group variable with if statement

I'm trying to set the variable group according to one varible that exists in the pipeline. The yaml looks like this:

enter image description here

But i'm getting the following error when i'm running the pipeline:

enter image description here

If i remove the "- group : QA" or "- group : PROD" the pipeline runs without any problem. What am I doing wrong?

like image 447
Bino Avatar asked Jan 25 '23 04:01

Bino


1 Answers

This is slightly different solution but you may achieve your goal - which is if I understood conditional selection of variable group.

You can use runtime parameters:

parameters:
- name: environment
  displayName: Environment
  type: string
  default: QA
  values:
  - QA
  - PROD

stages:
- stage:
  displayName: 'Build and Restore'
  variables:
  - group: ${{ parameters.environment }}
  jobs:
    - job:
      steps:
      - script: echo $(name)

than running a build you can select your envrionment:

Running a build

Note: I have defined two variable groups QA and PROD with variable name in both groups.

like image 171
Krzysztof Madej Avatar answered Feb 01 '23 22:02

Krzysztof Madej