0

How do I use output variables in Azure DevOps release pipeline gates?

I would like to output a variable equal to the value of something in the response of the HTTP request.

e.g. The http request will return { success: true, userId: 12345 }. I would like to set a variable for userId which I can use in the next HTTP request gate.

Output variables input box

2 Answers2

0

Maybe this isn't what you are looking for, but you can use Azure Powershell to invoke HTTP Request and output the value of response that way to a pipeline variable for use in subsequent steps.

Refer to this Stack Overflow Post: How to access the response of the InvokeRestAPI task from another job in an Azure DevOps pipeline?

$url = "https://vsrm.dev.azure.com/thecodemanual/$env:SYSTEM_TEAMPROJECTID/_apis/Release/definitions/$($env:RELEASE_DEFINITIONID)?api-version=5.0"
$pipeline = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Bearer
$env:SYSTEM_ACCESSTOKEN"}

Write-Host "Pipeline = $($pipeline | ConvertTo-Json -Depth 100)"
$buildNumber = $env:BUILD_BUILDNUMBER
$pipeline.variables.ReleaseVersion.value = $buildNumber

####****************** update the modified object **************************
$json = @($pipeline) | ConvertTo-Json -Depth 99
$updatedef = Invoke-RestMethod -Uri $url -Method Put -Body $json -ContentType "application/json" -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
Trent Tamura
  • 1,079
  • 6
  • 16
  • I don't think I can do this as I am trying to do this from a gate in a release pipeline which isn't using YAML. Thanks though – Tom Andrews Apr 20 '21 at 07:19
0

As of this time, however, outputting variables in Invoke REST API in gates is not supported.

The output variables section cannot output the custom defined variables, but only the variables defined by the task.

Unfortunately, this task does not define an output variable. You can see it in the screenshot:

There are no output variables associated with this task.

Jane Ma-MSFT
  • 4,461
  • 1
  • 6
  • 12