Today I needed to use the TFS API to get the last successful green build info from TFS so I thought whilst I'm still learning PowerShell I'll give it a go in that.  Anyway here's what I came up with, I could have condensed the lines but whilst I was debugging in PowerShellGUI (which is REALLY good for PowerShell development!) I wanted to see what each method returned.

 

 [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")  
 [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")  
 [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Common")  
   
 $tfsCollectionUrl = "http://SERVERNAME:8080/tfs/COLLECTION"
 $server = new-object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(New-Object Uri($tfsCollectionUrl))
 $buildServer = $server.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
 $buildDetail = $buildServer.QueryBuilds("TEAM_PROJECT", "BUILD_DEFINITION_NAME") | where { $_.BuildDefinition.LastGoodBuildUri -eq $_.Uri } #| select BuildNumber
   

$buildDetail will contain an IBuildDetail object as described here: http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.client.ibuilddetail.aspx

 


Posted in: PowerShell , TFS , MSBuild  Tags:

Comments


United Kingdom Matt Law
November 8. 2011 14:31
Matt Law
Very nice Smile Thanks for sharing!

no site

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Calendar

«  May 2012  »
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910
View posts in large calendar

Recent Comments

Banners

Theme Grabber
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012 Dan Gibbons .Net Developer