Automatically update test plan with build number, take 2
A while back I wrote a PowerShell script to automatically update a test plan with the latest build number (http://blogs.msmvps.com/molausson/2014/09/16/automatically-update-test-plan-with-build-number).
This script works well as long as the build server has permission to read and update test plans. But in some environments (such as when running on a hosted build agent in VSO) we need to do an explicit authentication. The solution I’ve choosen is to simply pass in credentials to the script and do an authentication before using the TFS API.
The script now takes two optional parameters if you want to authenticate, username and password, and you can just pass them in from the build definition. You can use ether basic authentication and pass both or use the safer option and pass a Personal Access Token (PAT) in which case you only pass the PAT as the password.
Here’s an example where you go to manage your credentials in Visual Studio Online. First go to your profile:
From the Security tab you can either create a Personal Access Token:
Press Add to create an access token:
Copy the PAT (it cannot be retrieved later):
If you want to use basic authentication go to the Alternate authentication section and fill in the secondary username and password:
With this you are ready to use the script. Download the latest version from here: https://github.com/tfsbuildextensions/CustomActivities/blob/master/Source/Scripts/UpdateTestPlanBuildNumber.ps1
Check in the script to Source control and update a Xaml build definition to use the script. In the following example I’ve used a PAT and only pass the token as the password:
Check out the old post if you want a step-by-step instruction on how to setup the build and test plan.