我如何知道谁破坏了 TFS 2010 中的最后一个版本 [英] How do I get who broke the last build in TFS 2010

查看:24
本文介绍了我如何知道谁破坏了 TFS 2010 中的最后一个版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


有没有办法查询谁破坏了 TFS 2010 中的最后一个版本.
我知道可以订阅构建失败事件,但我想查询 TFS 以获取上次构建和构建状态,以及如果它破坏了,是谁破坏了它.

Hi
Is there a way to query who broke the last build in TFS 2010.
I know that it is possible to subscribe to the build failed event but I would like to query the TFS to get the last build and the state of the build and if it broke, who broke it.

/吉米

推荐答案

以下代码将为您提供最新版本.这是 TFS2008,但在 TFS2010 下调用应该也能正常工作.

The following code will get you the most recent build. This is TFS2008, but the call should work fine under TFS2010 as well.

    public static IBuildDetail GetMostRecentBuild(TeamFoundationServer tfs, string teamProject, string buildName)
    {
        IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));

        IBuildDetailSpec buildDetailSpec = buildServer.CreateBuildDetailSpec(teamProject, buildName);

        buildDetailSpec.MaxBuildsPerDefinition = 1;
        buildDetailSpec.QueryOrder = BuildQueryOrder.FinishTimeDescending;
        buildDetailSpec.Status = BuildStatus.Failed | BuildStatus.PartiallySucceeded | BuildStatus.Stopped | BuildStatus.Succeeded;

        IBuildQueryResult results = buildServer.QueryBuilds(buildDetailSpec);

        if (results.Failures.Length != 0)
        {
            throw new ApplicationException("this needs to go away and be handled more nicely");
        }

        if (results.Builds.Length == 1)
        {
            return results.Builds[0];
        }
        else
        {
            return null;
        }

    }

不过,尝试查看谁破坏了构建不会那么简单.您需要做的是遍历 results.Builds[] 数组并找到最后一个有效的构建.完成后,您可以查询团队项目以获取自上次成功构建以来发生的所有变更集.以下代码将允许您这样做:

Trying to see who broke the build isn't going to be that straightforward, though. What you're going to need to do is down through the results.Builds[] array and find the last build that worked. Once you have that, you can query the team project for all changesets that have occurred since the last successful build. The following code will allow you to do that:

    public static List<Changeset> GetChangesetsSinceDate(TeamFoundationServer tfs, DateTime date, string path)
    {
        VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

        VersionSpec versionFrom = GetDateVSpec(date);
        VersionSpec versionTo = GetDateVSpec(DateTime.Now);

        IEnumerable results = vcs.QueryHistory(path, VersionSpec.Latest, 0, RecursionType.Full, "", versionFrom, versionTo, int.MaxValue, false, true);


        List<Changeset> changes = new List<Changeset>();

        foreach (Changeset changeset in results)
        {
            changes.Add(changeset);
        }

        return changes;
    }

    private static VersionSpec GetDateVSpec(DateTime date)
    {
        //Format is Dyyy-MM-ddTHH:mm  example:  D2009-11-16T14:32
        string dateSpec = string.Format("D{0:yyy}-{0:MM}-{0:dd}T{0:HH}:{0:mm}", date);
        return VersionSpec.ParseSingleSpec(dateSpec, "");
    }

这将为您提供可能破坏构建的候选变更集列表.这些将是您想要与之交谈的人.

This will give you the list of candidate changesets that may have broken the build. These would be the people you would want to talk to.

这可能是你想要的.您可以尝试通过将构建日志中失败的项目与变更集中的文件进行匹配来尝试做一些魔术,但这意味着解析出一个潜在的大型构建日志文件.

That's probably as far as you would want to go with this. You could try to do some magic by matching up the failed project in the buildlog to the files in the changesets, but that's going to mean parsing out a potentially large build log file.

这篇关于我如何知道谁破坏了 TFS 2010 中的最后一个版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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