Azure DevOps YAML Pipeline - Parse and Read variable map values in YAML

Copper Contributor

I am trying to consume, parse and read individual values from a YAML Map type object within an Azure DevOps YAML pipeline.
I am trying to do this all in YAML, rather than complicate things with terminal/PowerShell tasks and then the necessary additional code to pass it back up.

Ideals
-Minimal code to parse and read key pair value.
-No additional environment or pipeline variables to pass to further stages after parsing.

Example below of what I am trying to achieve. The example results in no value being printed see here.
Any help greatly appreciated.

 

variables.yml

variables:
  TF_VAR_MAPS: |
    Group1:
      name1: value1
      name2: value2
    
    Group2:
      name10: value10
      name11: value11

 

pipeline.yml

variables:
- template: variables.yml

stages:
- template: sub-pipeline.yml
  parameters:
    testVar1: ${{ variables.TF_VAR_MAPS.Group1.name1 }}
    testVar2: ${{ variables.TF_VAR_MAPS.Group2.name11 }}

 

sub-pipeline.yml

parameters:
    testVar1: ''
    testVar2: ''

stages:
- stage: TestStage1
  displayName: TestStage1
  jobs:
  - job: Job1
    displayName: Job1
    steps:
    - task: PowerShell@2
      inputs:
        targetType: 'inline'
        pwsh: true
        script: |
          Write-Host 'TestValue1: ' '${{ parameters.testVar1 }}'
          Write-Host 'TestValue2: ' '${{ parameters.testVar2 }}'

 

 

0 Replies