如何在powershell中获取当前的构建定义

时间:2014-06-24 07:27:14

标签: powershell

我有代码,在powershell上获得最后一次成功的构建定义。如何更改显示上次构建的代码。或者如果正在构建,请显示当前构建?

 [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://servertfs:8080/tfs/Test"
 $server = new-object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(New-Object Uri($tfsCollectionUrl))
 $buildServer = $server.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
 $buildDetail = $buildServer.QueryBuilds("NameProject", "NameBuildDefinition") | where { $_.BuildDefinition.LastGoodBuildUri -eq $_.Uri } #| select BuildNumber
 $buildDetail 

1 个答案:

答案 0 :(得分:1)

只需删除将结果限制为“上次成功构建”的过滤器,即可获取所有构建并从中应用适当的过滤器:

$buildDetail = $buildServer.QueryBuilds("NameProject", "NameBuildDefinition") | sort -desc StartTime | select -first 1
$buildDetail | ft BuildNumber, StartTime, Status

额外: 您可能希望查看使用builddetailspec并指定MaxBuildsPerDefinition,因为如果性能有问题可能会更快:http://www.incyclesoftware.com/2012/09/fastest-way-to-get-list-of-builds-using-ibuildserver-querybuilds-2/

(编辑:MaxBuildsPerDefinition本身将获得第一个构建,但在某个地方开始)