Get a list of all Releases in TFS or Visual Studio Team Services

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).

Create personal access token in VSTS VSO

Copy the personal access token and use it as a parameter to the script.

Copy personal access token

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.

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s