Azure DevOps Server 2020.1.1 API - How to get a build including the agent it ran on

Viewed 79

I am using an instance of BuildHttpClient of the nuget package Microsoft.TeamFoundationServer.Client to get my builds. Unfortunately the fetched objects of type Build do not include the name or id of the agent used to ran the build.

The property Queue just contains informations about the used queue, but not about the specific agent. There's another property AgentSpecification, but this seems to be always empty.

I could probably parse the attached logs of a build, but that would be pretty cumbersome.

1 Answers

Yes, that's an issue. However, as a workaround, you can try to extract that information from the logs. Small example:

var logs = BuildClient.GetBuildLogsAsync(TeamProjectName, buildId).Result;

foreach(var log in logs)
{
    var lines = BuildClient.GetBuildLogLinesAsync(TeamProjectName, buildId, log.Id).Result;

    foreach (var line in lines)
        if (line.Contains("Agent")) Console.WriteLine(line);                    
}

Result:

enter image description here

Related