TFS 2015 Build badges

Too much time since my last post I need to spend on my regular job. In last few days I was able to connect the regular work with my personal interest and I was working on TFS 2015 Build system for NAV. First two days I have spend on extending GitExtensions client with TFS 2015 Build connection (, other days with fine-tuning my PowerShell scripts and build template to build my databases correctly (scripts not published yet). And I really love the TFS 2015 Update 2, because it adds small but interesting things, like possibility to create build definition directly from the Code page (git repository) etc.

My target was to have simple table somewhere with all the build latest statuses. Because TFS 2015 supports the Markdown syntax, I decided to use it for creating the table as widget in my TFS Dashboard together with the badge functionality (more about it e.g. here). But of course, I do not want o write the text manually, because I will need to update it when new build will be created. What to do? Of course, I love PowerShell! Thus, there is the short script, which reads the build definitions through TFS REST API, generate the Markdown text and put it into your clipboard. Than you can just put the text into the Markdown widget and you are done! Of course, you can write the text into text file, commit and push it into git repository and connect the widget to this file, if you want. The result is same:

Status is clickable and will open the build definition.

And there is the script for you:

$tfsurl = 'http://<servername>:8080/tfs/<collection>'
$project = '<project name>'

$defs=(Invoke-RestMethod -Method GET -Uri "$tfsurl/$project/_apis/build/definitions?api-version=2.0&type=Build" -UseDefaultCredentials).value | Sort-Object -Property name

$Result = "|Build|Status|`n"
$Result += "|-----|------|`n"
$maxcount = 18
$i = 0
$start = 1
foreach ($d in $defs) {
    $url = "$tfsurl/_apis/public/build/definitions/$($$($"
    $weburl = "$tfsurl/$project/_build?definitionId=$($"
    $Result += "|$($|[![status]($url)]($weburl)|`n"
    if ($i % $maxcount -eq 0) {
        $result | clip
        Read-Host -Prompt "Press Enter to continue (lines $start to $i are in your Clipboard now)"
        $Result = "|Build|Status|`n"
        $Result += "|-----|------|`n"
        $start = $i+1
$result | clip
Write-Host "Lines $start to $i are in your Clipboard now"

I hope that I will find time to blog more about the build system itself. But I am really sorry for the delay.


29.6.2016: === Update===

I have updated the script to "page" the output. It will split the output to $maxcount of lines and put it into your clipboard with prompt for continue to be able to fill e.g. two Gadgets on the TFS Dashboard if you have too many build definitions.

No Data
Comment Children
No Data