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

}