1
votes

I have a series of release pipelines on Azure DevOps that are used to release different repos through our environments. Some of these releases stop at local, some on staging and a few go all the way to live. For tracking, I want to see which release version has gone to each environment. I can get a list of all releases by using the address described here: https://docs.microsoft.com/en-us/rest/api/azure/devops/release/releases/list?view=azure-devops-rest-5.1, but what I'd like to do is do the equivalent of Azure DevOps's "Currently Deployed" filter.

releases image

Any ideas?

1

1 Answers

1
votes

There doesn't seem to be a single source in the API to get the equivalent view. See this github issue here.

Following the conversation in github, once you have a handle on what environments exist in your release definitions. You can do it by making multiple calls to the deployments endpoint.

PowerShell example:

param (
    [string]$token,
    [string]$collection,
    [string]$projectName
)

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $token)))
$response = Invoke-RestMethod "https://vsrm.dev.azure.com/$collection/$projectName/_apis/release/definitions?`$expand=Environments&`$top=100&api-version=5.1" -Method 'GET' -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo)}

foreach ($releaseDefinition in $response.value){
   write-host $releaseDefinition.name
   write-host "--------------------------------------------------"
   foreach ($environment in $releaseDefinition.environments){
       write-host $environment.name
       $definitionEnvironmentId = $environment.id
       $response = Invoke-RestMethod "https://vsrm.dev.azure.com/$collection/$projectName/_apis/release/deployments?api-version=5.0&deploymentStatus=succeeded&latestAttemptsOnly=true&definitionEnvironmentId=$definitionEnvironmentId&`$top=1" -Method 'GET' -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo)}
       write-host $response.value[0].release.name $response.value[0].deploymentStatus $response.value[0].completedOn
   }
   write-host "--------------------------------------------------"
}