Querying the agent a build step was run on from Azure DevOps via REST API

Viewed 52

I need to extract information from a finished pipeline build in Azure DevOps. I can get the tree of steps in the executed plan for that build and the attached logs. The final piece of information that I'm looking for is the name of the build agent that was used to execute a certain step. How can I query the agent? The web frontend clearly shows the info, but I don't see it exposed via the documented API.

1 Answers

Querying the agent a build step was run on from Azure DevOps via REST API

First, there are Use predefined variables, which provide a list of predefined variables. You could use the Agent.Name to get the name of the build agent.

If you want to use REST API to get the name of it, you could use the REST API Builds - Get Build Log:

GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/logs/{logId}?api-version=6.0

Then we need to parse the log to get the name of the agent:

enter image description here

Related