skip to Main Content

I have a DevOps variable group with a variable like that: VARIABLE=['a', 'b', 'c'].

Then in Azure pipeline, there is a parameter like that:

parameters:
- name: parameter_test
  displayName: 'Test paramter'
  type: string
  default: a 
  values:
  - a
  - b
  - c

I want to use the variable instead of the hardcoded list, since it’s present in multiple pipelines. Tried this, but docs say I can’t use expressions in parameters section:

parameters:
- name: parameter_test
  displayName: 'Test paramter'
  type: string
  default: a 
  values:
- ${{ each group in variables.VARIABLE }}:
  - ${{ group }}

Have you ever tried things like that or have any idea how to parametrize it?
Thanks for any help!

2

Answers


  1. All non yaml files is not recommended as this is not as code, very difficult to check & audit & versionning, so as to variable group, release pipeline etc.

    Azure pipeline has indeed some limitations, we can reuse the variables but not the parameters.

    If I was you, even multiple pipelines use the same parameter, I will still "hard code" this directly in the pipelines just like what you wrote:

    parameters:
    - name: parameter_test
      displayName: 'Test paramter'
      type: string
      default: a 
      values:
      - a
      - b
      - c
    
    Login or Signup to reply.
  2. According to this document Variable groups for Azure Pipelines – Azure Pipelines | Microsoft Docs, to reference a variable group, use macro syntax or a runtime expression, therefore the parameter cannot be defined with the value of variable from a variable group.

    Instead of defining the parameter with the value of the variable in a variable group, you may consider using a core YAML to transfer the parameter/variable value into a YAML Template. Kindly refer to the below sample YAML pipeline.

    # Core YAML
    trigger:
    - none
    pool:
      vmImage: ubuntu-latest
    variables:
    - name: Variable_core
      value: b
    parameters:
    - name: Parameter_core
      default: c
      values:
        - a
        - b
        - c
    steps:
      - template: Parameters.yml
        parameters:
          parameter_test_Azure_Repos_1: ${{ variables.Variable_core }}
          parameter_test_Azure_Repos_2: ${{ parameters.Parameter_core }}
    
    # Parameters.yml from Azure Repos
    parameters:
    - name: parameter_test_Azure_Repos_1
      displayName: 'Test Parameter 1 from Azure Repos'
      type: string
      default: a
    - name: parameter_test_Azure_Repos_2
      displayName: 'Test Parameter 2 from Azure Repos'
      type: string
      default: a
    steps:
    - script: |
        echo ${{ parameters.parameter_test_Azure_Repos_1 }}
        echo ${{ parameters.parameter_test_Azure_Repos_2 }}
    

    echo b & c

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search