Search code examples
c#tfstfs-2015

How to determine, from TFS 2015, with C#, projects which have successful builds?


Is it possible (from C#/.Net) to acquire details of successful TFS builds, without knowing the project ?

I have tried using (a variant of) the following code, which works, but needs the project:

using Microsoft.TeamFoundation.Build.WebApi;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Core.WebApi;

private async Task<Boolean> HasSuccessfulBuilds(TeamProjectReference project)
{
    using (var ttpc = new TfsTeamProjectCollection(new Uri(collectionUri)))
    {
        using (var buildClient = ttpc.GetClient<BuildHttpClient>())
        {
            var results = await buildClient.GetBuildsAsync(project: project.Id, resultFilter: BuildResult.Succeeded);
            return results.Any();
        }
    }
}

This works, but only if I supply the project. If I don't specify the (optional?) project parameter (to GetBuildsAsync), I get an exception:

"The guid specified for parameter projectId must not be Guid.Empty."

What I would like to do, is offer the user the ability to select a project/build definition/build/etc., but only for the projects/etc. where there has been a successful build.

At the moment, I can find all projects, and then only list the ones where there has been a successful build (see above code), but that's many roundtrips (1 per project), and I was hoping to start from successful builds (and work up).

Thanks.


Solution

  • Your proposed solution (look at every Team Project) is correct. Builds are scoped at a Team Project level, and there is no API to query builds at the Team Project Collection (TFS) / account (VSTS) level.