TFS:查询包含特定变更集的内部版本 [英] TFS: Query for builds containing a specific changeset

查看:227
本文介绍了TFS:查询包含特定变更集的内部版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多基于TFS中单个分支(例如Main)执行的构建定义。

I have a number of build definitions that get executed based upon a single branch in TFS (eg Main).

我想(以某种方式)查询TFS查找包含我提供的特定变更集编号的所有构建,并返回TFS包含的构建名称的字符串列表。

I'd like to (somehow) query TFS to find all builds containing a specific changeset number that I supply, and return a list of string of the names of the builds that TFS contains. Any kind of app (VS extension, CLI app, winforms, whatever) will do.

注意:这不是请给我提供代码的请求;而是任何应用程序(VS扩展程序,CLI应用程序,winforms,等等)都可以。我愿意为此做准备并认真工作。有关如何查询数据库或SDK的文档的任何指针,或有关如何查询内部版本的示例的任何指针;只是一个开始寻找的地方会非常有帮助。谢谢。

Note: this isn't a 'plz give me the code' request; I'm willing to hoof it and do serious work on this. Any pointers to documentation on how to query the database or SDK, or an example of how to query builds; just some place to start looking would be extremely helpful. Thanks.

推荐答案

以下代码段将抓取集合中所有团队项目的所有构建定义,并检查每个构建对于与输入变更集编号的关联:

The following snippet will crawl all Build Definitions of all Team Project of a Collection, and will check each and every build for an Association to the input changeset number:

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

namespace FindChangesetInBuild
{
    class Program
    {
        static void Main(string[] args)
        {
            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://tfs:8080/tfs/collectionName"));

            var versionControl = teamProjectCollection.GetService<VersionControlServer>();
            var buildService = (IBuildServer)teamProjectCollection.GetService(typeof(IBuildServer));

            var teamProjects = versionControl.GetAllTeamProjects(true);
            foreach (var teamProject in teamProjects)
            {
                var buildDefinitions = buildService.QueryBuildDefinitions(teamProject.Name);
                foreach (var buildDefinition in buildDefinitions)
                {
                    var builds = buildService.QueryBuilds(buildDefinition);
                    foreach (var buildDetail in builds)
                    {
                        var changesets = InformationNodeConverters.GetAssociatedChangesets(buildDetail);
                        if (changesets.Any(changesetSummary => changesetSummary.ChangesetId == Convert.ToInt32(args[0])))
                        {
                            Console.WriteLine("Changeset was build in "+buildDetail.BuildNumber);
                        }
                    }
                }
            }
        }
    }
}

不用说,这是蛮力攻击。
如果缩小 buildDefinition的列表,您可以进一步优化代码,着重于特定的 teamProjects 等。无论如何,我几乎无法想象上面的内容是有用的!

(显然) MSDN , TFS-SDK的绝佳资源是Shai Raiten的博客
对于构建专有示例,请同时检查此处& 此处一些可能有趣的SO帖子。

Needless to say, this is a brute force attack.
You can further refine the code if you narrow down the list of buildDefinition, make focus on specific teamProjects etc. In any case I can hardly imagine the above to be useful as-is!

Apart from (obviously) MSDN, a great resource for TFS-SDK is Shai Raiten's blog.
For Build-Speficic examples, check also here & here for some possibly interesting SO posts.

这篇关于TFS:查询包含特定变更集的内部版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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