TFS: Query for builds containing a specific changeset

依然范特西╮ 提交于 2019-12-06 00:47:34

问题


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

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.

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.


回答1:


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);
                        }
                    }
                }
            }
        }
    }
}

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.




回答2:


You can use this little DB Query in TFS 2010 and just substitute 90264 with your changeset id.

USE Tfs_Warehouse
go
SELECT BuildName 
FROM DimBuild
   INNER JOIN FactBuildChangeset
   ON DimBuild.BuildSK = FactBuildChangeset.BuildSK
WHERE FactBuildChangeset.ChangesetSK = 90264


来源:https://stackoverflow.com/questions/10019522/tfs-query-for-builds-containing-a-specific-changeset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!