Fetching build definitions from Visual Studio Online through TFS API

前端 未结 2 593
孤独总比滥情好
孤独总比滥情好 2020-12-21 03:53

I\'m having a problem retrieving build information from a Visual Studio Online project through the TFS API. I can connect to the project, it seems, and find the expected tea

相关标签:
2条回答
  • 2020-12-21 04:15

    You can utilize the BuildHttpClient to make similar requests as you would with the 2.0 REST API.

    This sample on GitHub is a pretty good resource, if you would rather poll a single project it should look something more like this:

    using System;
    using System.Collections.Generic;
    using Microsoft.TeamFoundation.Build.WebApi;
    using Microsoft.VisualStudio.Services.Client;
    
    static void GetBuildStatus()
    {
        var tfsUrl = "http://<tfs url>:<port>/tfs/<collectionname>";
        var buildClient = new BuildHttpClient(new Uri(tfsUrl), new VssAadCredential());
        var definitions = buildClient.GetDefinitionsAsync(project: "<projectmame>");
        var builds = buildClient.GetBuildsAsync("<projectname>";
    
        foreach (var build in builds.Result)
        {
            Console.WriteLine(String.Format("{0} - {1} - {2} - {3}", build.Definition.Name, build.Id.ToString(), build.Status.ToString(), build.StartTime.ToString()));
        }
    }
    
    0 讨论(0)
  • 2020-12-21 04:23

    I believe you are right I have just tested your code against my own VSO on a GIT project and I cannot retrieve any build.vNext builds, however I can retrieve old XAML build definitions.

    I then tried using the REST API and it too could only return the old style XAML builds until I got it to use version 2 of the REST API and then the XAML and build.vNext style builds came back. Here is an example string I tried in my browser (make sure you are logged into VSO first to test it)

    https://[vsoname].visualstudio.com/defaultcollection/[project]/_apis/build/definitions?api-version=2.0
    
    0 讨论(0)
提交回复
热议问题