Since you're working with Classic pipelines, and you're trying to retrieve the Agent Specification, The Azure DevOps REST API does NOT currently expose the "Agent Specification" (e.g., windows-latest, ubuntu-20.04) for Classic pipelines — even when using Microsoft-hosted agents.
In Classic pipelines, when you choose a Microsoft-hosted agent, you select an Agent pool e.g., Azure Pipelines, and then choose an "Agent Specification" e.g., windows-2022 via the UI dropdown.
However, this "Agent Specification" value is stored internally as a demand, but the Build Definitions API only returns the pool ID/name - it doesn't expose that capability.
For classic pipelines, the manual way to find the agent specification is Go to Azure DevOps -> Pipelines -> Pipeline -> Edit -> Triggers -> YAML Tab.
If you want to know what image was used in the most recent run, you can query the last build:
GET https://dev.azure.com/{org}/{project}/_apis/build/builds/{buildId}?api-version=7.1-preview.7
You can see the output as agentSpecification.identifier
. It is only present if it was a Microsoft-hosted agent.
Additional References:
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/Builds/Get?view=azure-devops-rest-7.1
Hope this helps!
Please Let me know if you have any queries.
If you found the information helpful, please click "Upvote" on the post to let us know and consider accepting the answer as the token of appreciation. Thank You.