Number of build definitions

If you are stuck on upgrading to TFS 2018 due to the old deprecated XAML based builds, it can be a challenge to see how far you are from the goal of zero XAML builds.

First we need to get all projects in a collection:

$TFSProjects = (Invoke-RestMethod -Uri ($TFSServerURL + '/_apis/projects?api-version=1.0') -Method GET -UseDefaultCredentials).value | sort Name

Then we iterate through these and get alle build definitions and print out the counts for each build type.

#Get build definitions per TFS project
foreach ($Project in ($TFSProjects))
{
    $builddefinitions = (Invoke-RestMethod -Uri ($TFSServerURL + '/' + $project.name +  '/_apis/Build/definitions?api-version=2.0') -Method GET -UseDefaultCredentials).value
    If ($builddefinitions.count -ne 0)
    {
        Write-host $Project.name -ForegroundColor Green    
        $builddefinitions | group type | select name, count  | out-string
    }
 }

Please note that it doesn’t look at what kind of XAML build it is. It can be a compile build or deployment for Lab.

Full script:

 $TFSServerURL = "HTTP://[TFSCollectionURL]"
 
#Get projects
$TFSProjects = (Invoke-RestMethod -Uri ($TFSServerURL + '/_apis/projects?api-version=1.0') -Method GET -UseDefaultCredentials).value | sort Name

#Get build definitions per TFS project
foreach ($Project in ($TFSProjects))
{
    $builddefinitions = (Invoke-RestMethod -Uri ($TFSServerURL + '/' + $project.name +  '/_apis/Build/definitions?api-version=2.0') -Method GET -UseDefaultCredentials).value
    If ($builddefinitions.count -ne 0)
    {
        Write-host $Project.name -ForegroundColor Green    
        $builddefinitions | group type | select name, count  | out-string
    }
 }

Author: KimC

TFS admin and deployment fellow

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s