Azure Devops: Get Build Pipeline Status programmatically

Mansi Vijh 1 Reputation point Microsoft Employee
2021-08-16T20:13:44.413+00:00

Need a way to obtain the status of a build pipeline given just the definition id and not the build run id i.e. some way of getting the last run status or multiple status values of last few runs.
Came across the Get status api. Able to query the same using Postman, but have two questions:

  1. This seems to only return the response in the form of a badge(svg). Any way to obtain just a simple xml/json response?
  2. Getting the following exception when hitting the equivalent api via .NET library. Tried using the GetStatusBadgeAsync API in the BuildHTTPClient in TFS but getting the following error message: {“Invalid response content type: image/svg+xml Response Content: <svg width=\"180.8\" height=\"20.0\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <linearGradient id=\"a\" x2=\"0\" y2=\"100%\">\r\n <stop offset=\"0.0\" stop-opacity=\"0.0\" stop-color=\"#000\" />\r\n <stop offset=\"1.0\" stop-opacity=\"0.2\" stop-color=\"#000\" />\r\n </linearGradient>\r\n <clipPath id=\"c\">\r\n <rect width=\"180.8\" height=\"20.0\" rx=\"3.0\" />\r\n </clipPath>\r\n <g clip-path=\"url(#c)\">\r\n <rect width=\"180.8\" height=\"20.0\" fill=\"#555555\" />\r\n <rect width=\"68.9\" height=\"20.0\" fill=\"#4EC820\" x=\"111.9\" />\r\n <rect width=\"180.8\" height=\"20.0\" fill=\"url(#a)\" />\r\n </g>\r\n <svg width=\"12\" height=\"12\" viewBox=\"0 0 12 12\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\" x=\"5\" y=\"4\">\r\n <g>\r\n <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M0 9H1V11H3L3 12H0V9Z\" fill=\"#fff\" />\r\n <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M0.666656 4H3.7352L6.20309 0.444336C6.38861 0.166992 6.70068 0 7.03479 0H11.5C11.7762 0 12 0.224609 12 0.5V4.96484C12 5.29883 11.8332 5.61133 11.5553 5.79688L8 8.26465V11.333C8 11.7012 7.70154 12 7.33334 12H5L4 11L5.25 9.75L4.25 8.75L2.99997 10L1.99997 9L3.25 7.75L2.25 6.75L1 8L0 7V4.66699C0 4.29883 0.298462 4 0.666656 4ZM10.5 3C10.5 3.82812 9.82843 4.5 9.00003 4.5C8.1716 4.5 7.50003 3.82812 7.50003 3C7.50003 2.17188 8.1716 1.5 9.00003 1.5C9.82843 1.5 10.5 2.17188 10.5 3Z\" fill=\"#fff\" />\r\n </g>\r\n </svg>\r\n <g fill=\"#fff\" text-anchor=\"middle\" font-family=\"DejaVu Sans,Verdana,Geneva,sans-serif\" font-size=\"11\">\r\n <text x=\"64.9\" y=\"15.0\" fill=\"#000\" fill-opacity=\"0.3\">Azure Pipelines</text>\r\n <text x=\"64.9\" y=\"14.0\" fill=\"#fff\">Azure Pipelines</text>\r\n <text x=\"145.4\" y=\"15.0\" fill=\"#000\" fill-opacity=\"0.3\">succeeded</text>\r\n <text x=\"145.4\" y=\"14.0\" fill=\"#fff\">succeeded</text>\r\n </g>\r\n</svg>"}

Code for triggering the api:

var buildClient = await this.connection.GetClientAsync<BuildHttpClient>(cancellationToken).ConfigureAwait(false);  
var buildBadge = await buildClient.GetStatusBadgeAsync(this.project, buildDefinitionId.ToString(), null, null, null, null, null, null, cancellationToken).ConfigureAwait(false);  
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,614 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Dave Patrick 426.2K Reputation points MVP
    2021-08-16T20:16:15.467+00:00

    Devops / TFS is not currently supported here on Q&A. The product group for Azure DevOps / TFS actively monitors questions over at
    https://developercommunity.visualstudio.com/report?space=21&entry=problem
    https://developercommunity.visualstudio.com/report?space=22&entry=problem

    --please don't forget to upvote and Accept as answer if the reply is helpful--

    1 person found this answer helpful.
    0 comments No comments