6

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!

Boologne
  • 175
  • 1
  • 11

3 Answers3

6

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.

Here is my test with postman: enter image description here enter image description here

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.

enter image description here enter image description here

Hugh Lin
  • 17,829
  • 2
  • 21
  • 25
  • Hi. Thanks for the fast reply. I am getting this response if I specify a PipelineId: ```width : 152.4 height : 20.0 xmlns : http://www.w3.org/2000/svg linearGradient : linearGradient clipPath : clipPath g : {g, g} svg : svg``` Can you share your response? – Boologne Sep 27 '19 at 07:47
  • The response body returned by this rest api is in the form of an image, not returning the result in json format.This can be seen from the response body I got in postman. – Hugh Lin Sep 27 '19 at 08:39
  • 1
    @o_boo At present, this rest api still has limitations.So I provided a second method,please see my update,although this is still not perfect. – Hugh Lin Sep 27 '19 at 10:49
  • Thanks. Then I have to wait until a proper API is available, because I need a stable version of it to have it in an AzDO extension. As long as multi stage pipelines are in preview, I cannot expect, that everything is in place. – Boologne Sep 28 '19 at 06:13
  • Is there any guidance on restricting PAT permissions for the second method? I can't seem to get it to work with anything but full access, but I really don't want to give it full access. – F.A. Feb 04 '22 at 14:01
4

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.
Joel Bourbonnais
  • 2,618
  • 3
  • 27
  • 44
0

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();
Maroine Abdellah
  • 576
  • 1
  • 5
  • 21