5

I have a yaml pipeline, using the task Azure Powershell Task https://learn.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 Answers 2

4

just reference it like any other variable:

$(output)

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#set-in-script

Sign up to request clarification or add additional context in comments.

1 Comment

yes, I referenced it, but the missing part was that I skipped converting the string output to json. Thank you
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.