0

test_env_template.yml

variables:
- name: DB_HOSTNAME
  value: 10.123.56.222
- name: DB_PORTNUMBER
  value: 1521
- name: USERNAME
  value: TEST
- name: PASSWORD
  value: TEST
- name: SCHEMANAME
  value: SCHEMA  
- name: ACTIVEMQNAME
  value: 10.123.56.223
- name: ACTIVEMQPORT
  value: 8161

and many more variables in the list.

I wanted to iterate through all the variables in the test_env_template.yml using a loop to replace the values in a file, Is there a way to do that rather than calling each values separately like ${{ variables.ACTIVEMQNAME}} as the no. of variables in the template is dynamic.

JCDani
  • 307
  • 7
  • 20

1 Answers1

0

In short no. There is no easy way to get your azure pipeline variables specific to tamplet variable. You can get env variables, but there you will get regular env variables and pipeline variables mapped to env variables.

You can get it via env | sort but I'm pretty sure that this is not waht you want.

You can't display variables specific to template but you can get all pipeline variables in this way:

steps:
- pwsh: 
    Write-Host "${{ convertToJson(variables) }}"

and then you will get

{
   system: build,
  system.hosttype: build,
  system.servertype: Hosted,
  system.culture: en-US,
  system.collectionId: be1a2b52-5ed1-4713-8508-ed226307f634,
  system.collectionUri: https://dev.azure.com/thecodemanual/,
  system.teamFoundationCollectionUri: https://dev.azure.com/thecodemanual/,
  system.taskDefinitionsUri: https://dev.azure.com/thecodemanual/,
  system.pipelineStartTime: 2021-09-21 08:06:07+00:00,
  system.teamProject: DevOps Manual,
  system.teamProjectId: 4fa6b279-3db9-4cb0-aab8-e06c2ad550b2,
  system.definitionId: 275,
  build.definitionName: kmadof.devops-manual 123 ,
   build.definitionVersion: 1,
  build.queuedBy: Krzysztof Madej,
  build.queuedById: daec281a-9c41-4c66-91b0-8146285ccdcb,
  build.requestedFor: Krzysztof Madej,
  build.requestedForId: daec281a-9c41-4c66-91b0-8146285ccdcb,
  build.requestedForEmail: krzysztof.madej@hotmail.com,
  build.sourceVersion: 583a276cd9a0f5bf664b4b128f6ad45de1592b14,
  build.sourceBranch: refs/heads/master,
  build.sourceBranchName: master,
  build.reason: Manual,
  system.pullRequest.isFork: False,
  system.jobParallelismTag: Public,
  system.enableAccessToken: SecretVariable,
  DB_HOSTNAME: 10.123.56.222,
  DB_PORTNUMBER: 1521,
  USERNAME: TEST,
  PASSWORD: TEST,
  SCHEMANAME: SCHEMA,
  ACTIVEMQNAME: 10.123.56.223,
  ACTIVEMQPORT: 8161
}

If you prefix them then you can try to filter using jq.

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