1

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.

roli09
  • 817
  • 1
  • 8
  • 20

1 Answers1

2

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

roli09
  • 817
  • 1
  • 8
  • 20
Shamrai Aleksander
  • 13,096
  • 3
  • 24
  • 31
  • 1
    Thanks for your help. I had already implemented it that way, but then I found out, that the logs are gone as soon as somebody deletes a build. Because I wanna do a daily "snapshot" of how many, when and how long builds have been ran, I went with another approach. I found out, that you can get all job requests of the agents with an api call ([see here](https://stackoverflow.com/questions/54206874/azure-devops-rest-api-get-builds-currently-queued-in-agent-pool)). Because the job requests contains the build id, you can ref them. – roli09 Dec 14 '21 at 12:15