Reputation: 315
Until now, I am using the Azure DevOps REST Api to get the data from releases in Azure DevOps for reporting purpose. Obviously, this will change with the new way how to use CI/CD --> YAML and the Multi-Stage-Pipeline (currently preview). In that case the build- and release-strategy is deprecated and everything is defined as a pipeline and subdivided into staged (build stage, deploy stage 1, deploy stage 2, ...).
I tried to receive data via the build list method, but this data is limited and I am missing some important information like 'was stage successful'.
Does anybody have already experience with the compination of YAML Pipelines and the Azure DevOps REST Api? Is there a way to get the full data (as with classic release strategy)? Or is it currently under development and I have to be patient?
Thanks in advance!
Upvotes: 8
Views: 9051
Reputation: 642
thank you for the hint, Joel is right, you will get all the records, so you will need only to filter on the Stage type to get all the stages of your pipeline
If you are using the C# wrapper you can use this code=>
var buildClient = connection.GetClient<BuildHttpClient>();
var timeline = await buildClient.GetBuildTimelineAsync(project.Name, buildDef.LatestBuild.Id);
var stageTimelines = timeline.Records.Where(record => record.RecordType == "Stage").ToList();
Upvotes: 0
Reputation: 2718
It seems the Timeline API was made exactly for that.
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/timeline/{timelineId}?api-version=7.1-preview.2
Documentation can be found here.
An array of records is returned with a status for every Phase, Stage, Job, Task & Checkpoint.
As for the {timelineId}
, it is not a required field, as opposed to the default example, and not providing one yields proper results. It seems it could come from a previous attempt:
Name | Type | Description |
---|---|---|
timelineId | string | Gets or sets the timeline identifier which owns the record representing this attempt. |
Upvotes: 7
Reputation: 19471
How to get stage results from YAML pipelines in Azure DevOps
For this issue, you need to use Status - Get rest api.
GET https://dev.azure.com/{organization}/{project}/_apis/build/status/{definition}?api-version=5.1-preview.1
This api can get the build status for a definition, optionally scoped to a specific branch, stage, job, and configuration.
Update Second way:
You can press F12
in the browser then select Network
to capture the request to get the stage result.You can capture the result from the response body. But different stage results are represented by different numbers i.e 0->completed,5->canceled etc.
Upvotes: 6