I have a customer that is transitioning from the old version of Release Management to the new one. The question today was, how he can get an overview of all releases in all projects that are going on.
I don’t think this is possible yet with the UI – so I cam up with a small script that uses the REST API to get the releases. The script gets all projects for a project collection and retrieves all the releases for each project. It then sorts the output and displays it as a table.
You could also dump it to a json and display it in a html site if you want to display the releases in a dashboard.
[CmdletBinding()] Param ( [Parameter(Mandatory=$true, Position=0)] $ProjectCollection ) $projectsResult = Invoke-RestMethod "$ProjectCollection/_apis/projects?api-version=1.0" -Method Get -UseDefaultCredentials $releases = @() $projectsResult.value | % { $project = $_.name $url = "$ProjectCollection/$project/_apis/release/releases?api-version=2.2-preview.1" $result = Invoke-RestMethod $url -Method Get -UseDefaultCredentials if ($result.count -gt 0){ $result.value | % { $releases += [pscustomobject]@{ Project = $project Name = $_.Name Status = $_.status CreatedOn = [datetime]$_.createdOn ModifiedOn = [datetime]$_.modifiedOn } } } } $releases | Sort-Object -Property ModifiedOn -Descending | Format-Table -AutoSize
If you want to use the same technique in VSTS you have to create a personal access token first. The good thing with personal access tokens is, that you can restrict access to certain features (like Release (read)) and revoke access later.
To create the token click under you Name on My Security and create the token with the correct permissions (see image).
Copy the personal access token and use it as a parameter to the script.
Here is the script to get the releases in VSTS.
[CmdletBinding()] Param ( [Parameter(Mandatory=$true, Position=0)] $Account, [Parameter(Mandatory=$true, Position=1)] $Accesstoken ) $passkey = ":$($Accesstoken)" $encodedKey = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($passkey)) $token = "Basic $encodedKey" $projectsResult = Invoke-RestMethod "https://$Account.visualstudio.com/_apis/projects?api-version=1.0" -Method Get -Headers @{ Authorization = $token } $releases = @() $projectsResult.value | % { $project = $_.name $url = "https://$Account.vsrm.visualstudio.com/$project/_apis/release/releases?api-version=3.0-preview.2" $result = Invoke-RestMethod $url -Method Get -Headers @{ Authorization = $token } if ($result.count -gt 0){ $result.value | % { $releases += [pscustomobject]@{ Project = $project Name = $_.Name Status = $_.status CreatedOn = [datetime]$_.createdOn ModifiedOn = [datetime]$_.modifiedOn } } } } $releases | Sort-Object -Property ModifiedOn -Descending | Format-Table -AutoSize
Note that the URL points to vsrm.visualstudio.com and that the api version is also different.
If one of the scripts does not work then check the current state of the api version in the REST documentation.
Hello,
Is there a way to filter releases by date and by environment (for example getting all releases of today and deployed to production)?
You can filer the output with $releases | where { $_.Prop -eq ‘val’ } | sort-object…
If you want to filter the release in the web request you can filter using request parameters (like definitionEnvironmentId or minCreatedTime).
See https://www.visualstudio.com/en-us/docs/integrate/api/rm/releases for more details.
Indeed, it’s a good solution.
The problem is that I do not have the informations I want by simply calling “_apis/release/releases?api-version=2.2-preview.1”. In fact, I have to call “_apis/Release/releases/18” to get the value of “environment”… 😥
Did you find a solution for your problem? You can expand i.e the environments like this: https://fabfiber-inc.vsrm.visualstudio.com/MyFirstProject/_apis/Release/definitions?%24expand=Environments
Hi there,
can you provide me the example of $ProjectCollection?
Thanks.
How can I get all releases? ran your script I could get current month only. Thanks.
The project collection is the first part of the url: https://dev.azure.com/{organization} for Azure DevOps or http[s]://{server[:port]}/tfs/{collection}.
Check out the docu here:
https://docs.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-6.1