3
votes

I have a yaml pipeline, using the task Azure Powershell Task https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-powershell?view=azure-devops

The script already has task output as follows:

$output = ConvertTo-Json -InputObject @{
    resourceName = "aseName"
    resourceGroupName = "ResourceGroupName"
} -Compress

Write-Output "##vso[task.setvariable variable=output;]$output"

In the subsequent task, within the same job. I need to use use it as {output.resourceName}. Typically from the designer it is possible to get it out the same way as I want. But with YAML I could not figure it out.

Any pointers?

2

2 Answers

0
votes

As a side note, which might save others some time in the future. When you create a new stage and want to reference your variable, you should also add "isOutput=true" when you're setting the variable:

Write-Output "##vso[task.setvariable variable=output;isOutput=true]$output"

And when referencing the Output variable in YAML, call the variable as such:

- stage: 
  displayName: someName
  variables: 
   output: $[stageDependencies.<stageName>.<jobName>.outputs['<stepname>.output']]
  jobs:
  - job: SomeName
    steps:
    - task: SomeTask