All posts by Mathias Olausson

Build Status Badge for TFS and Visual Studio Online

With the new Markdown support in Visual Studio Online you can easily create a great project Wiki with information relevant to your team. One nice thing to have there is the build status(es), which for instance the AppVeyor build system provides as a small image – a build badge. Here’s how that could look in a Wiki page:

image 

Adding the build badge is done by simply including an image element in the Markdown page:

image

I really like how easy it is to create mashups of different services to visualize data for the team using Markdown.

As for the build badge I think this is something that would be nice to have included in the product, if you think so too, vote on the following UserVoice suggestion:

image

But until that eventually happens we can always solve it ourselves. So what is needed to do this? It’s actually really simple, just write a service that looks up the build status and returns an image containing the badge.

In this example I’ve solved it by implementing a standard ASP.NET MVC application. I’ve used a controller that accepts a team project and build definition name as query string arguments:

http://<server>/build/badge?teamProject=<team-project>&buildDefinition=<build-definition>

for example;

http: //s-labtfs.cloudapp.net:9000/build/badge?teamProject=FeaturesInc&buildDefinition=FeaturesInc.CI

This request will return a .png image like this:

image

Ok, so how did I do this? Let’s look at the code.

To make it easy to generate the badge I’ve created 150×30 px images to draw the image. The Images folder contains a couple of images like the one below, which we’ll then draw the status text on.

image

The code to generate a badge image is implemented as a MVC controller action. The code below gets the details from the latest build, draws the badge image and finally returns it as an image/png stream as the result:

image

GetBadgeDetails is a small helper function to give us the data to render on the badge image:

image

Finally the DrawRoundedRectangle renders the bounding rectangle for the badge:

image

To get the build data we need a couple of references to TFS:

  • Microsoft.TeamFoundation.Build.Client.dll
  • Microsoft.TeamFoundation.Client.dll

The code to get the TFS build details is as simple as this:

image

That’s all. Build and deploy to your favorite IIS server and you’re ready to start serving build badges for your team!

Download the complete sample here.

Use Visual Studio Online + Markdown as your Wiki

With the latest deployment of VSO a bunch of great improvements for content editing was released. Take a look at http://www.visualstudio.com/en-us/news/2014-dec-17-vso for the complete list of additions.

The feature I’m most excited about in this update is the “Quick code editing” tools. With these changes we now have decent in-place editing capabilities in the VSO Web UI. It’s easy to add (new or upload) and edit files.

One thing I’ve been waiting for is the ability to use VSO for my team documentation in a Wiki-style way. Now the enchanced editing tools and the fact that VSO supports Markdown files I can finally do this in a good way. All my content is conveniently stored in version control, which makes authoring (using any tool) very easy. And I’ve got complete tracability as well, something that can be very useful when managing this kind of dynamic content.

Here is a quick walk-through just to show how easy it is to get started.

Add a welcome page

First we need to create a start page. Switch to the Welcome page on the VSO home page. Initially you will get a default page with an instruction on how to get started.

image

Click the Edit button and you will switch to the Markdown editor for the README.md file. In the example below I’ve added some initial content, including a link to the backlog for the team.

image

Use the preview tool to check out the layout before saving.

image

When you are happy with the page, save it and the README.md file will be added at the top-level in your repository.

image

Add content

Now with the start page in place it’s easy to add more content. If you add links to sub-pages you will get the option to automatically create them just like the welcome page.

Note: it’s a good idea to create a structure for your documents, in this case we’ll add the dev-handbook.md in the docs folder in source control.

image

Saving the README.md file now gives you a link to a page that doesn’t yet exist.

image

Click the link and you can add the page the same way as we did for the welcome page. When you have saved the file it also creates the folder structure for you:

image

Add images

Another nice feature in this VSO deployment is the ability to add files to version control directly from the web UI. This allows us to quickly add additional content, like for instance images, to the page. Select the node to add content to, right-click and select Add Files…

image

Next you can add new or existing items to that folder, in my case I’ll be adding a logo to our wiki.

image

I want the image on the welcome page so next I’ll edit the README.md file again and add a Markdown link to the image I’ve just uploaded to the repository.

image

Save the file and look at how nice the wiki looks with the image inplace.

image

Using external tools

If you want a richer editing experience then you can use any Markdown tool to author the content. The only big difference is that you need to sync the files in the repository yourself. But if you are a developer then using a TFVC or Git client is nothing new so that shouldn’t be a challenge. In the example below you can see what it looks like editing using MarkdownPad.

image

Happy editing!

TFS Work Item Tags Admin Tool

With the latest updates to TFS and Visual Studio 2013 it’s pretty conventent to use Tags on work items. But there are still a few quirks, like for instance that there is no tool to rename or delete a Tag in the UI (yes, there are APIs for it but obviously not a great option for managers, stakeholders and the likes). Unused tags are automagically removed from the list after a few days so for the patient user at least there’s an option.

But to help us with less patience I’m happy to see that fellow MVPs Tarun Arora and Utkarsh Shigihalli have built a Visual Studio extension that’s now been released to the Visual Studio gallery.

Get the extension here.

Tech Days 2014 – Continuous Delivery (SWE)

Tack ni som kom på min presentation på Tech Days! Det var kul att se det stora intresset för Continuous Delivery, något som jag känner är ett av de mest intressanta tillskotten inom software engineering eller utvecklingsprocesser under senare år. Rätt tillämpat kan det göra stor skillnad i hur snabbt man kan leverera sin produkt med bibehållen (eller förbättrad!) kvalitet.

Presentationen från sessionen finns nu uppe på SlideShare här.

För er som var intresserade av koden från projektet jag använde som demo så kan ni ladda ner den här.  Det är en komplett lösning med de olika komponenter och script som jag använde under presentationen. Jag kommer skriva en post här inom kort som går igenom lösningen steg för steg och visar hur man kan sätta upp en CD process som bygger, paketerar, deployar och testar.

PodCast: Vad kan man göra i Visual Studio Online? (SWE)

Förra veckan hade jag och Joachim Rossberg förmånen att vara med i Dag Königs Podcast-serie. Ämnet? Såklart något ALM-relaterat, denna gång pratade vi om Visual Studio Online (VSO) och vad denna molntjänst erbjuder oss som utvecklar mjukvara. Lyssna in på http://www.buzzfrog.se/index.php/2014/11/dev-cast-88-vad-kan-man-gra-i-visual-studio-online/ så får du höra vad vi kom fram till.

Brian Keller’s Visual Studio 2013 ALM VM Updated!

Yesterday Brian Keller released an update to the awesome virtual machine we all use for demoing Visual Studio, TFS and ALM.

The significant update in this release is that it’s been refreshed to VS/TFS 2013 Update 3. One of the major changes to the VM is that you also can use it to connect to Visual Studio Online, see the Connecting to Visual Studio Online Using the Visual Studio 2013 ALM Virtual Machine HOL for more details.

Read more about the update here: http://blogs.msdn.com/b/briankel/archive/2014/09/19/now-available-update-3-refresh-of-visual-studio-2013-alm-virtual-machine.aspx

Download the latest VM here: http://blogs.msdn.com/b/briankel/archive/2013/08/02/visual-studio-2013-application-lifecycle-management-virtual-machine-and-hands-on-labs-demo-scripts.aspx

Automatically update test plan with build number

A great feature in Microsoft Test Manager is that it allows you to track which application build your are running your tests against. This is useful for manual testing to track which tests was run against a particular build, it will be assigned to a bug reported during testing and it is used to locate test assemblies used for running automated tests.

It’s really simple to set this up, just go to the properties for the test plan and assign the build definition to the test plan:

image

Unfortunately you need to assign the Build in use manually, which is both tedious and easy to forget.

The solution to this is of course automation. The TFS 2013 build templates can easily be extended to run a post build script (typically PowerShell). See http://msdn.microsoft.com/en-us/library/vstudio/dn376353.aspx if you want to know more about how to run a script in the build process.

The script below will find all test plans in the team project where the build definition is used and update them with the latest build. All you need to do is add the script to source control and reference it in the build definition:

image

Running the build will update the test plans using the build definition to the latest build:

image

The latest version of the script is available from TFS Community Build Extensions on Github here: UpdateTestPlanBuildNumber.ps1. A snapshot is shown below:

##———————————————————————–

## <copyright file=”UpdateTestPlanBuildNumber.ps1″>(c) http://TfsBuildExtensions.codeplex.com/. This source is subject to the Microsoft Permissive License. See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx. All other rights reserved.</copyright>

##———————————————————————–

# Update all test plan using the current build definition with the latest build number.

#

  

# Enable -Verbose option

[CmdletBinding()]

  

# Disable parameter

# Convenience option so you can debug this script or disable it in

# your build definition without having to remove it from

# the ‘Post-build script path’ build process parameter.

param([switch]$Disable)

if ($PSBoundParameters.ContainsKey(‘Disable’))

{

   Write-Verbose “Script disabled; no actions will be taken on the files.”

}

  

# If this script is not running on a build server, remind user to

# set environment variables so that this script can be debugged

if(-not $Env:TF_BUILD -and -not ($Env:TF_BUILD_BUILDURI -and $Env:TF_BUILD_BUILDDEFINITIONNAME -and $Env:TF_BUILD_COLLECTIONURI))

{

   Write-Error “You must set the following environment variables”

   Write-Error “to test this script interactively.”

   Write-Error ‘$Env:TF_BUILD_BUILDURI – For example, enter something like:’

   Write-Error ‘$Env:TF_BUILD_BUILDURI = “vstfs:///Build/Build/15″‘

   Write-Error ‘$Env:TF_BUILD_BUILDDEFINITIONNAME – For example, enter something like:’

   Write-Error ‘$Env:TF_BUILD_BUILDDEFINITIONNAME = “MyProduct.Main.CI”‘

   Write-Error ‘$Env:TF_BUILD_COLLECTIONURI – For example, enter something like:’

   Write-Error ‘$Env:TF_BUILD_COLLECTIONURI = “http://localhost:8080/tfs/DefaultCollection”‘

   exit 1

}

  

# Make sure build uri is set

if (-not $Env:TF_BUILD_BUILDURI)

{

   Write-Error (“TF_BUILD_BUILDURI environment variable is missing.”)

   exit 1

}

Write-Verbose “TF_BUILD_BUILDURI: $Env:TF_BUILD_BUILDURI

 

# Make sure build definition name is set

if (-not $Env:TF_BUILD_BUILDURI)

{

   Write-Error (“TF_BUILD_BUILDDEFINITIONNAME environment variable is missing.”)

   exit 1

}

Write-Verbose “TF_BUILD_BUILDDEFINITIONNAME: $Env:TF_BUILD_BUILDDEFINITIONNAME

 

# Make sure tfs collection uri is set

if (-not $Env:TF_BUILD_COLLECTIONURI)

{

   Write-Error (“TF_BUILD_COLLECTIONURI environment variable is missing.”)

   exit 1

}

Write-Verbose “TF_BUILD_BUILDDEFINITIONNAME: $Env:TF_BUILD_BUILDDEFINITIONNAME

 

[Reflection.Assembly]::LoadWithPartialName(‘Microsoft.TeamFoundation.Client’)

[Reflection.Assembly]::LoadWithPartialName(‘Microsoft.TeamFoundation.TestManagement.Client’)

[Reflection.Assembly]::LoadWithPartialName(‘Microsoft.TeamFoundation.Build.Client’)

 

# Find all test plans using this build definition

$tpc = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($env:TF_BUILD_COLLECTIONURI)

$tcm = $tpc.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService])

$buildServer = $tpc.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])

$teamProject = $buildServer.GetBuild($Env:TF_BUILD_BUILDURI);

$testProject = $tcm.GetTeamProject($teamProject.TeamProject);

$testPlans = $testProject.TestPlans.Query(“SELECT * FROM TestPlan”)

 

$matchingTestPlans = @()

foreach($testPlan in $testPlans)

{

    if($testPlan.BuildFilter.BuildDefinition -eq $Env:TF_BUILD_BUILDDEFINITIONNAME)

    {

        $matchingTestPlans += $testPlan

    }

}

 

# Update test plans with latest build

if($matchingTestPlans)

{

   Write-Host “Will update test plans using $Env:TF_BUILD_BUILDDEFINITIONNAME to $Env:TF_BUILD_BUILDURI to $($matchingTestPlans.count) test plans.”

  

   foreach ($matchingTestPlan in $matchingTestPlans) {

     if(-not $Disable)

     {

        $matchingTestPlan.BuildUri = $Env:TF_BUILD_BUILDURI

        $matchingTestPlan.Save()

        Write-Verbose $matchingTestPlan.Name – version applied”

     }

   }

}

else

{

   Write-Warning “Found no test plans to update.”

}

 

Extending TFS Work Item using a web page and the WebpageControl Revisited

Update 140831: This article has been refreshed with new images and content.

Have you ever wanted to add custom behavior to the TFS work item tracking system? TFS is very flexible when it comes to adding fields, rules and state transitions. But when we need more specialized behavior there is usually only one solution – to implement custom work item controls. It’s pretty straight-forward to implement a work item control (http://witcustomcontrols.codeplex.com/ has some good examples), but we need to implement the control for each client we want to use it (Visual Studio, Web access) and also the control must be deployed to each machine where the client is run.

A much simpler approach can be to implement the extension as a web page and host the web page in the work item form. This solution works with any client (since it’s just a web page) so you won’t have to have one implement for each client type. In TFS 2010 the WebpageControl was introduced, which can be used to host a custom web page inside a work item form. We can configure the control to pass data from the work item to the web page when the control is displayed. So with the WebpageControl we can use the TFS API to write a web page that can surface more or less any data in the work item UI.

In this example I will extend the Test Case work item type with a tab that shows the test suites where the test case is used together with the status of the latest test run in each of the suites.

Note: it’s recommended to work with TFS customization in a sandbox environment so you don’t disturb production use of your TFS. A very easy way to get a development environment for TFS is to use Brian Keller’s Visual Studio / TFS 2012 virtual machine.

The WebpageControl isn’t that much documented on MSDN so I’m going take you through the steps of extending a work item type with the control and linking it to a custom web page.

1. Implement the web page for the extension you want. Since this is just a web application it’s simple to develop, debug and test the extension. Design the page so data can be passed from the work item to the page using URL parameters (http://localhost:9000/test/results?teamprojectName=Scrum2013&testCaseId=313 in this case).

image

2. Add a WebpageControl to the work item type. The easiest way to add a control is to use the Process Template Editor (part of the TFS Power Tools):

image

Make sure to set the Dock property to Fill if you want the control to use the whole tab space.

3. Configure the WebpageControl using the Control Settings:
Set the URL to display and other properties as appropriate:

image

Note the use of field names. You can reference any field with it’s unique reference id, for instance the Team Project name would be $(System.TeamProject).

4. Save and update the work item type definition. Refresh the client you are using to make sure the test case type definition has been updated.

5. Open a test case and see the new control with the custom web page content appear under the Test Suites tab.

image

Simple, wasn’t it? Feel free to leave comments on what you think of this approach.

Next up I will walk you through the code for the Test Results page.

TechDays 2014 (SWE) – Från kod till produktion på 60 minuter

I höst är det dags för nästa TechDays i Sverige, denna gång 18-20 november på Kistamässan i Stockholm.

Själv har jag förmånen att hålla ett pass om releasehantering som specifikt kommer att handla om hur man med hjälp av senaste versionen av Visual Studio kan sätta upp en releaseprocess på ett väldigt smidigt sätt. Vi kommer gå igenom hela flödet från kod till release och även få med stödjande tekniker som automatiserad testning och miljöhantering.

Info om sessionen hittar du här: http://www.techdays.se/Program/Sessioner/Fran-kod-till-produktion-pa-60-minuter-eller-hur-du-med-hjalp-av-Release-Management-for-Visual-Studio-kan-implementera-en-automatiserad-releaseprocess

Har du idéer på saker du skulle vilja se mer av inom release management så skriv en kommentar.

image