none
Get build definitions TFS2018 RRS feed

  • Question

  • Hi!

    I'm using TFS Api to get build definitions next way:

    var tfs = new TfsTeamProjectCollection(new Uri(collectionUri));
                var buildServer = tfs.GetService<IBuildServer>();
                var builds = buildServer.QueryBuildDefinitions(build.TeamProjectName);

    In TFS2013 this code works great and it returns definitions. But after updating to TFS 2018 it doesn't work - QueryBuildDefinitions always returns empty array with no errors. I'm using Nuget packages with 16 version. What should I do to get build definitions in TFS 2018? Or how to diagnose the problem?


    Thursday, August 9, 2018 12:37 PM

Answers

  • Hi!

    I'm using TFS Api to get build definitions next way:

    var tfs = new TfsTeamProjectCollection(new Uri(collectionUri));
                var buildServer = tfs.GetService<IBuildServer>();
                var builds = buildServer.QueryBuildDefinitions(build.TeamProjectName);

    In TFS2013 this code works great and it returns definitions. But after updating to TFS 2018 it doesn't work - QueryBuildDefinitions always returns empty array with no errors. I'm using Nuget packages with 16 version. What should I do to get build definitions in TFS 2018? Or how to diagnose the problem?


    Well, I found solution. It seems, TFS2018 does not support connecting via TeamFoundation.Client to build server. But REST API from the same library works great. Now I'm using this code:

                TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri(collectionUri));
                BuildHttpClient bhc = ttpc.GetClient<BuildHttpClient>();
                var builds = bhc.GetFullDefinitionsAsync(project: build.TeamProjectName).Result;
    There is only one problem - last version of Team Foundation  Client  requires System.Net.Http.Formatting 5.2.3, but my company using newer version 5.2.6 and I had to copy libraries of 5.2.3 just in build folder


    Friday, August 24, 2018 9:14 AM

All replies

  •  

     public string GetTFSJsonData(string url)
            {
                try
                {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    request.Credentials = new NetworkCredential( "UserName","Password","Domain");
                    request.Method = "GET";
                    request.ContentType = "application/json";
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                    Console.Write(response.StatusCode);
                    using (var streamReader = new StreamReader(response.GetResponseStream()))
                    {
                        return streamReader.ReadToEnd();
                    }
                }
                catch (Exception ex)
                {
                    // HandleException.LogException(ex);
                    return null;
                }
            }

    public List<Value> ListAllBuilds() { JSONHelper _jsonHelper = new JSONHelper(); string result = _jsonHelper.GetTFSJsonData("http://ServerName:8080/tfs/DefultCollection/TestProject/_apis/build/definitions?api-version=2.0"); if (!string.IsNullOrEmpty(result)) { return JsonConvert.DeserializeObject<AllBuildsList>(result).value.ToList(); } else { return new List<Value>(); } } public class Value { public int id { get; set; } public string name { get; set; } } public class AllBuildsList { public int count { get; set; } public IList<Value> value { get; set; } }



    Friday, August 10, 2018 6:31 PM
  • For TFS 2018, you may use TFS API Version 4.0, Check the compatibility

    "http://ServerName:8080/tfs/DefultCollection/TestProject/_apis/build/definitions?api-version=4.0""

    Friday, August 10, 2018 6:33 PM
  • Hi!

    I'm using TFS Api to get build definitions next way:

    var tfs = new TfsTeamProjectCollection(new Uri(collectionUri));
                var buildServer = tfs.GetService<IBuildServer>();
                var builds = buildServer.QueryBuildDefinitions(build.TeamProjectName);

    In TFS2013 this code works great and it returns definitions. But after updating to TFS 2018 it doesn't work - QueryBuildDefinitions always returns empty array with no errors. I'm using Nuget packages with 16 version. What should I do to get build definitions in TFS 2018? Or how to diagnose the problem?


    Well, I found solution. It seems, TFS2018 does not support connecting via TeamFoundation.Client to build server. But REST API from the same library works great. Now I'm using this code:

                TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri(collectionUri));
                BuildHttpClient bhc = ttpc.GetClient<BuildHttpClient>();
                var builds = bhc.GetFullDefinitionsAsync(project: build.TeamProjectName).Result;
    There is only one problem - last version of Team Foundation  Client  requires System.Net.Http.Formatting 5.2.3, but my company using newer version 5.2.6 and I had to copy libraries of 5.2.3 just in build folder


    Friday, August 24, 2018 9:14 AM