代理的 TFS 构建持续时间报告 [英] TFS build duration report by agent

查看:36
本文介绍了代理的 TFS 构建持续时间报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个报告来显示我的各种构建代理的相对效率,但在从工具中获取我需要的信息时遇到了问题.

I'm trying to build a report to show the relative efficiency of my various build agents and having trouble getting the info I need out of the tool.

我想要的是一个包含以下列的简单网格:

What I'd like to have is a simple grid with the following columns:

  • 版本号
  • 构建定义
  • 构建代理
  • 构建状态
  • 构建开始时间
  • 构建持续时间

这会让我做一些类似的事情,比如将给定构建定义在 agent1 上成功构建的持续时间与通过 agentN 在 agent2 上的相同构建定义进行对比.

Which would let me do something like chart the duration of successful builds of a given build definition on agent1 against the same build definition on agent2 through agentN.

我该怎么做?

推荐答案

我最初的意图是向您指出 TFS OLAP Cube &描述你如何找回你想要的东西.然后我意识到多维数据集没有提供代理构建了什么构建的信息.

然后我认为编写一个小型的 TFS 控制台应用程序来打印您想要的信息会很简单:

My initial intention was to point you to TFS OLAP Cube & describe how you could retrieve what you were after. Then I realized that the cube does not provide with the info which Agent built what Build.

Then I thought it would be simple to write a small TFS-console app that print the infos you 're after:

using System;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Client;

namespace BuildDetails
{
    class Program
    {
        static void Main()
        {
            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://TFS:8080/tfs/CoLLeCtIoNNaMe"));
            var buildService = (IBuildServer)teamProjectCollection.GetService(typeof(IBuildServer));

            IBuildDefinition buildDefinition = buildService.GetBuildDefinition("TeamProjectName", "BuildDefinitionName");
            IBuildDetail[] buildDetails = buildService.QueryBuilds(buildDefinition);

            foreach (var buildDetail in buildDetails)
            {
                Console.Write(buildDetail.BuildNumber+"\t");
                Console.Write(buildDefinition.Name+"\t");
                Console.Write(buildDetail.BuildAgent.Name+"\t");
                Console.Write(buildDetail.Status+"\t");
                Console.Write(buildDetail.StartTime+"\t");
                Console.WriteLine((buildDetail.FinishTime - buildDetail.StartTime).Minutes);                
            }           
        }
    }
}

这不会编译,因为


最终我深入到 IBuildInformationNode[] 并获得了构建代理,如下所示:

This won't compile, since


Eventually I dove into the IBuildInformationNode[] and got the build agent as follows:

IBuildInformation buildInformation = buildDetail.Information;
IBuildInformationNode[] buildInformationNodes = buildInformation.Nodes;
string agentName;
try
{
  agentName = buildInformationNodes[0].Children.Nodes[3].Fields["ReservedAgentName"];
}
catch
{
  agentName = "Couldn't determine BuildAgent";
}
Console.Write(agentName + "\t");

try-catch 是必要的,因此您可以处理在代理选择之前失败/停止的构建.

如果您使用后一部分来替代失败的 Console.Write(buildDetail.BuildAgent.Name+"\t"); 你应该最终得到一个控制台应用程序,它的输出可以通过管道传输到一个 *.CSV 文件中 &然后导入到 Excel.

The try-catch is necessary, so you can deal with builds that failed/stopped before agent-selection.

If you use this latter part as a substitute to the failing Console.Write(buildDetail.BuildAgent.Name+"\t"); you should end up with a console app, whose output can be piped into a *.CSV file & then imported to Excel.

这篇关于代理的 TFS 构建持续时间报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆