Requirement: Need to capture the current or running build pipeline result using REST API at the end of the same build pipeline.
- I have 3 build pipelines for 3 different environments and each build having 3 different stages(Stage1, Stage2, Stage3).
- I need to get the current running build's final stage (Stage3) results (whether succeeded/failed).
- I need to get that result information post final stage, i would like to run PS script as next task/job or Post job to capture the result of final stage whether it has passed/failed using Rest API.
- I have PS script ready and I would like to know exact API which can be used for this scenario.
Challenge: I'm at half stage, I'm having challenge in getting the final stage' result for that particular running build at the end of the same build pipeline.
Example code snippet:
$personalAccessToken=(Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name $secretname).SecretValueText
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($personalAccessToken)"))
$header = @{Authorization=("Basic {0}" -f $token)}
$projectsUrl = "https://dev.azure.com/$AzureDevopsAccount/$Project/_apis/build/builds?api-version=5.0&resultFilter=all&definitions=$definition"
$projects = Invoke-RestMethod -Uri $projectsUrl -Method Get -Headers $header
Write-Host "Pipeline = $($projects.value.result| ConvertTo-Json -Depth 1)"
Using this code, I'm able to capture the result for all pipelines. I just need to know how to get the status of the running build at the end of pipeline completion.
Note: As I have 3 different build pipelines, I need to be able to separately capture this result for all 3 builds at the end of each build pipeline.
Any suggestions will be appreciated. Thanks.