CodeMonkey
CodeMonkey

Reputation: 12444

How to get a pipeline run error with Azure runs REST API

I'm using Azure's Runs API to get a pipeline run result as described here:

https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/get?view=azure-devops-rest-6.0#runresult

I can see in the documentation how to get the state and final result so I can know if the run was a success or a failure. However, in case of a failure, I don't see how I can get the error that occurred in that run as a string.

How can I get the actual error which caused the pipeline run to fail?

Upvotes: 1

Views: 1594

Answers (1)

Bright Ran-MSFT
Bright Ran-MSFT

Reputation: 13944

You can use the REST API "Timeline - Get" to list the issues (error and warning) associated with a run.

Note: This API can only list the first 10 issues. If the run has more than 10 issues, the rest will not be listed in the response. To get the complete issues, you can use the API "Builds - Get Build Log" or "Logs - Get" to get the complete logs that contains the complete issues.

[UPDATE]

The buildId is same as the runId, and you can find it from the URL of the pipeline (build) run.

The timelineId is not required in the API request, you can use the request URI like as below.

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

Upvotes: 2

Related Questions