如何确定给定构建在TFS中使用哪个构建代理?

时间:2016-06-14 17:41:28

标签: tfs tfsbuild

我有以下查询,这是非常有用的总体,但我似乎无法确定我的构建使用的构建代理。 注意: - 现在这是基于@ Patrick-MSFT提供的出色帮助的工作代码。

TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("***"));
IBuildServer buildServer = (IBuildServer) tfs.GetService(typeof (IBuildServer));
var buildDetail = buildServer.CreateBuildDetailSpec("Team Project","Dev-CI"); 
buildDetail.MinFinishTime = DateTime.Now.Date.AddDays(-2);
var buildResult = buildServer.QueryBuilds(buildDetail).Builds.Dump();
buildInformation.Nodes.Where (i => i.Type == "ActivityTracking").FirstOrDefault ().Children.Nodes.Where (n => n.Type == "AgentScopeActivityTracking").FirstOrDefault ().Fields["ReservedAgentUri"].Dump("Agent");

1 个答案:

答案 0 :(得分:1)

构建将分配给任何在线代理。构建完成后,您应该能够从IBuildDetail的信息(IBuildInformation)属性中获取代理信息。您可以尝试使用以下类型获取节点:InformationTypes.AgentScopeActivityTracking FieldInformationFields.ReservedAgentName FieldInformationFields.ReservedAgentUri Field

示例代码:

 IBuildInformation buildInformation = buildDetail.Information;
 IBuildInformationNode[] buildInformationNodes = buildInformation.Nodes;
 string agentUri = buildInformationNodes[0].Children.Nodes[3].Fields["ReservedAgentUri"];
 IBuildAgent buildAgent = buildService.GetBuildAgent(new Uri(agentUri));

您可以参考类似问题的详细信息:TFS build duration report by agent