Kine's Info

What I found and what I know about Microsoft Dynamics NAV

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 (https://github.com/kine/gitextensions), 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) {
    $i++
    $url = "$tfsurl/_apis/public/build/definitions/$($d.project.id)/$($d.id)/badge"
    $weburl = "$tfsurl/$project/_build?definitionId=$($d.id)"
    $Result += "|$($d.name)|[![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.

  • Thanks. Be working with different source code and release systems before, something homemade for the classic. Going to test VS TFS out for my new project. Been "eating" all the Youtube's and blog's I could find over the last week. But still didn't quite understand exactly how to use these build extensions for NAV....

  • I see the reason why to write new blog article regarding that... :-)

  • Will be looking forward to that Kamil. :)  One thing (among many others) that I don't understand is, why do you need these special scripts. Couldn't we do the exact same thing, using "standard" PowerShell scripts? And will the above work with Visual Studio Online also?

  • The scripts are using the "standard" cmdlets inside, but you need to do many things around, like reading some settings (like where is the DB backup, license etc.) to not have them fixed somewhere etc. Thus it is better to create the special scripts used in the build process. In this way you do not need so many steps in the build definition and you can handle different things easily. And yes, it is working with VSO, but you need own Agent on your machine to build NAV, because you cannot use the VSO agents when you need to install something on the build server (you need to install NAV there...). But the agent could be connected to VSO (or Team Foundation Service, I do not know which the name is actual/correct).