Myke
Myke

Reputation: 51

How to get the current stage running in an Azure DevOps pipeline build?

Using this endpoint only shows overall pipeline run status:

https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs/{runId}

Using this endpoint can check stage status, but not of a specific run:

https://dev.azure.com/{organization}/{project}/_apis/build/status/{definition}?stageName=[stage]

I want to get the current stage running in a pipeline build in Azure DevOps. So for example, there are multiple runs ongoing, I want to be able to get which stage each run is in.

Upvotes: 2

Views: 2939

Answers (2)

rudi belt
rudi belt

Reputation: 201

Using the sample at https://devblogs.microsoft.com/premier-developer/how-to-retrieve-all-work-items-associated-with-a-release-pipeline-using-azure-devops-api/ I was able to check if the production stage was run (to generate release notes) using:

var timeline = buildClient.GetBuildTimelineAsync(project: projectName, buildId: buildItem.Id).Result;

var prodTimeline = timeline.Records.Where(r => r.RecordType == "Stage" && r.Name == "Deploy to prd" && r.Result == TaskResult.Succeeded).FirstOrDefault();
               


               

Upvotes: 1

Myke
Myke

Reputation: 51

Found a way using the timeline endpoint: https://dev.azure.com/$ORGANIZATION/$PROJECT/_apis/build/builds/$BUILDID/timeline?api-version=6.0

Then parsing the records array, to get the stages and their current state.

Upvotes: 3

Related Questions