0

I am trying to get a list of Vnext builds run using C# and BuildHttpClient but unable to retrieve them. However, the XAML Builds show up.

Does BuildHttpClient not recognize Vnext Builds? Some forums suggest using REST API for TFS but i am looking for sample piece of code.

Any help appreciated!

Praveen
  • 29
  • 6

1 Answers1

0

I test at my side, it can get the Vnext build via BuildHttpClient.

  1. Install Microsoft Team Foundation Server Extended Client package, then it will add necessary assemblies automatically.
  2. Create project and try below code to get a list of the Vnext builds for TFS 2017:

    using Microsoft.TeamFoundation.Build.WebApi;
    
    using Microsoft.VisualStudio.Services.WebApi;
    
    using Microsoft.VisualStudio.Services.Common;
    
    using System;
    using System.Net;
    
    namespace GetBuild
    {
        class Program
        {
            static void Main(string[] args)
    
            {
                var u = new Uri("http://win-kev006:8080/tfs/DefaultCollection/");
                VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.WindowsCredential(new NetworkCredential("user", "password", "domain"))); 
                var connection = new VssConnection(u, c);
                var buildServer = connection.GetClient<BuildHttpClient>();
                var builds = buildServer.GetBuildsAsync("LCTFVCScrum").Result; 
                for (int i = 0; i < builds.Count; i++)
                {
                    Console.WriteLine(string.Format("  number: {0} -result: {1} - status: {2}", builds[i].BuildNumber, builds[i].Result.ToString(), builds[i].Status.ToString()));
                }
    
            }
        }
    }
    

The REST API is as below:

GET https://{instance}/DefaultCollection/{project}/_apis/build/builds?api-version={version}

https://www.visualstudio.com/en-us/docs/integrate/api/build/builds#work-items

Kohei TAMURA
  • 4,970
  • 7
  • 25
  • 49
Andy Li-MSFT
  • 28,712
  • 2
  • 33
  • 55
  • @Praveen Any update for the solution? have you resolved your issue? – Andy Li-MSFT Jun 15 '17 at 05:46
  • I used the Github resource https://github.com/Microsoft/GetVSTSBuildUsage which uses the same concept. Thanks for your inputs. – Praveen Jun 16 '17 at 14:00
  • @Praveen However you can try following above steps to get the VNext builds if the Github resource not work, I tested above code at my side, it works correctly. – Andy Li-MSFT Jun 19 '17 at 10:31
  • @Praveen Could you please [Mark it as Answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) or post your solution/workaround here and Mark it as Answer.This can be beneficial to other community members reading this thread. – Andy Li-MSFT Jun 20 '17 at 01:09
  • I could, but i don't have enough Reputation, so stackoverflow is not allowing me to mark it as helpful, Sorry. – Praveen Jun 20 '17 at 18:30