0

I have a YAML template with parameters:

  - name: Deploy_Test1
    type: boolean
    default: false
  - name: Tests
    type: object
    default:
      - "Test1"
      - "Test2"

After that I iterate the Tests with each:

- ${{ each test in parameters.Tests}}:

Inside the each I can get the test value with ${{test}}.

I want to use the parameter Deploy_Test1 but dynamically, for example:

echo ${{ parameters.Deploy_${{test}} }} 

In the above syntax I get an error that is invalid.

Is there is a way or a workaround to do it?

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114

1 Answers1

1

You need to use two loops here and check if you find your key.

parameters:
- name: Deploy_Test1
  type: boolean
  default: false
- name: Tests
  type: object
  default:
    - "Test1"
    - "Test2"

trigger: none

pool:
  vmImage: ubuntu-latest

steps:
- ${{ each test in parameters.Tests}}:
  - ${{ each parameter in parameters }}:
    - ${{ if eq(parameter.key, format('Deploy_{0}', test)) }}:
      - script: echo ${{ parameter.value }}

And then you will get:

enter image description here

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107