1

Original question

Is it possible to store the response from a REST API call in a variable and use it in the downstream jobs?

Question update:

I want to store the resolved value through a PowerShell script, and make it accessible through out the next stages. I have setup a script like this:

$slot = &"c:\temp\GetSlot.exe" 2>&1
Write-host "resolved:" $slot
Write-host "init value output:" $(currentslot)

Write-Output ("##vso[task.setvariable variable=currentslot;isOutput=true;]$slot")
Write-host "updated value output:" $(currentslot)

Along with a variable, to make it accessible throug the $(currentslot) in aditional stages. Its configured like this:

Stages: enter image description here

The value from the executions is being set into the $slot variable, but the variable is not getting updated, what do I do wrong?

1 Answer 1

1

yes, you would use regular way of doing so:

Write-Host "##vso[task.setvariable variable=containerName]$containerName"
                                            ^             ^ variable content (string)
                                            ^ variable name in downstream tasks

you can also use yaml to share variables between phases (https://github.com/MicrosoftDocs/vsts-docs/blob/master/docs/pipelines/process/multiple-phases.md)

create\update release through api: https://learn.microsoft.com/en-us/rest/api/azure/devops/release/definitions/create?view=azure-devops-rest-5.0 (it has variables property)

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

5 Comments

Thanks @4c74356b41, I updated the question - cant quite get this to work.
define next stages?
Updated question with stage definition.
ok, that wont work, it will only work in the same build\stage. you would need to use ADO rest api to create\update those variables
Okay, thanks a lot. I think i am going to determine the the value on each stage to keep it simple. But thanks for clarifying the possibilities for me.

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.