Naweap
Naweap

Reputation: 105

TFS API - How to get project builds from a dedicated build server

I'm developing a software to return all builds of a TFS project stored in a collection. The particularity of the current TFS infrastructure is the build server. It's a dedicated server (remote server and used only for building). So the third line of the following code is not working for me because in my case, the build "service" is not located on the TFS server directly :

Uri uri = new Uri("urlToTFS");
TfsConfigurationServer tfs = TfsConfigurationServerFactory.GetConfigurationServer(uri);
IBuildServer buildServer = tfs.GetService<IBuildServer>();

Do you guys have any idea to instance a build server object from a dedicated build server ? By providing the build server name or by getting a property of the TFS server ?

Thank you in advance.

Upvotes: 1

Views: 1540

Answers (1)

PatrickLu-MSFT
PatrickLu-MSFT

Reputation: 51183

The APIs in Microsoft.TeamFoundationServer.ExtendedClient are primarily there to supply backward compatibility with legacy XAML builds.

For the new build system you need to use REST API to get list of builds. A code snippet for your reference:

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

You could take a look at this similar question: TFS server API only list the XAML build definitions

Upvotes: 0

Related Questions