0

As I am new to yaml and powershell,Can someone please help me in understanding the way of using a variable of one Yaml in another one?

Example Scenario:

I have variable- $a in abc.yml under the folder-Test1,now I have to use the same $a in bcd.yaml under the folder -Test2.

How can I achieve this in powershell?

Divya
  • 9
  • 4
  • I think it might be useful if you provide more information about the use case, like how are you using powershell to call one or the other – Ked Mardemootoo Jun 03 '21 at 13:04
  • https://learn.microsoft.com/en-us/samples/azure-samples/azure-pipelines-variable-templates/azure-pipelines-variable-templates/ – Shayki Abramczyk Jun 03 '21 at 13:12

1 Answers1

0

To pass params between yml files in Azure DevOps you have to specify a path to the template (the file you want to pass the param across to) and give the parameter a value. Then in the second file also declare the parameter.

To make use of the param it in the second yaml you can use the ${{parameters.name}} construction:

Let's assume $a represents a directory path...

Example contents of abc.yml:

stages:
- stage: 'Passing param example'
  jobs:
  - template: ${{variables['System.DefaultWorkingDirectory']}}/bcd.yml
    parameters:
      param1_butuseanynameyoulike: $a

The in the bcd.yml:

parameters:
  - name: 'param1_butuseanynameyoulike'
    displayName: 'Parameter passed from original yaml file'
    type: string
    default: ''

jobs:
  - job: somename

    steps:
        - task: PowerShell@2
          inputs:
            targetType: 'inline'
            script: |
              Get-ChildItem -Path ${{ parameters.param1_butuseanynameyoulike }}"

committhisgit
  • 110
  • 1
  • 6