TFS: Query for builds containing a specific changeset

左心房为你撑大大i 提交于 2019-12-04 07:47:13
pantelif

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.

Stu

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