Search code examples
tfstfs-2015

Obtaining Information About Web Style Builds via the API


We are moving to the web style builds on TFS 2015 (Update 4).

I've always been able to retrieve information about builds using the code below, but that is not retrieving our new builds created via the web interface.

Is there a reasonable way to modify my code to bring in both legacy builds and the new style builds?

If not, I assume it is time for me to figure out how to use the REST API. Any tips for an equivalent query would be appreciated.

TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("http://SERVERINFO"));
IBuildServer buildServer = (IBuildServer) tfs.GetService(typeof (IBuildServer));

var buildDetail = buildServer.CreateBuildDetailSpec("*");
buildDetail.MinFinishTime = DateTime.Now.Date.AddDays(-1);
buildDetail.InformationTypes = null;
buildDetail.QueryDeletedOption = QueryDeletedOption.IncludeDeleted;
buildDetail.MaxBuildsPerDefinition = 1; //Only return the most recent of each build type...or comment out to return all builds with this definition

var builds = buildServer.QueryBuilds(buildDetail).Builds.Select(....

Solution

  • The old XAML build system uses a SOAP API.The task-based new vNet build system does not have a SOAP API. It's using REST API. I'm afraid you could not just modify the code to get new builds. They do not support Build vNext as they were written before their time.

    Besides the SOAP API is slowly being replaced with a REST API, especially in some new features.Since you are moving to vNext build on TFS2015 update4. Highly recommend you stat to use Rest API.

    You can access it from C# code either by querying the REST API directly or by using the Team Foundation Server Client NuGet package. A Sample:

    using System;
    using System.Collections.Generic;
    using Microsoft.TeamFoundation.Client;
    using Microsoft.TeamFoundation.Build.WebApi;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Uri tfsurl = new Uri("http://xxxx:8080/tfs/CollectionName");
                TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(tfsurl);
                BuildHttpClient bhc = ttpc.GetClient<BuildHttpClient>();
                List<Build> builds = bhc.GetBuildsAsync("ProjectName").Result;
                foreach (Build bu in builds)
                {
                    Console.WriteLine(bu.BuildNumber);
                }
                Console.ReadLine();
            }
        }
    }
    

    By using the Rest API in the libraries as above, you could be able to get both XAML and vNext builds.