I have a YAML release pipeline which triggers from a build pipeline. I want to get the details about the consumed artifacts via REST API. E.g., Consumed artifacts of all types such as repositories, builds, etc as shown below:
I tried the Runs - Get REST API: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/get?view=azure-devops-server-rest-7.0 But it seem to return the consumed artifacts of only repository type.
I attempt with the same REST API "Runs - Get", and it can correctly return the resource pipeline as expected.
The YAML of the pipeline. The YAML pipeline will be automatically triggered once a run of the resource pipeline (MathCalc
in below sample) is completed successfully.
# azure-pipelines.yml
resources:
pipelines:
- pipeline: MathCalc
source: MathCalc
trigger: true
. . .
Call the REST API "Runs - Get" in PowerShell script.
# get-pipleine-run.ps1
$organization = "Organization Name"
$project = "Project Name"
$pipelineId = 174
$runId = 3818
$uri = "https://dev.azure.com/${organization}/${project}/_apis/pipelines/${pipelineId}/runs/${runId}?api-version=7.0"
$pat = "Personal Access Token"
$base64Token = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "", $pat)))
$headers = @{Authorization = "Basic $base64Token"}
$response = Invoke-RestMethod -Method GET -Uri $uri -Headers $headers
$response | ConvertTo-Json -Depth 10 | Out-File -FilePath run-$runId.json
EDIT:
I also tried the REST API "Runs - Get" on my Azure DevOps Server 2022, and it also can return the resource pipeline as expected.
The YAML pipeline with schedules trigger.
# azure-pipelines.yml
trigger: none
schedules:
- cron: '54 6 * * *'
displayName: 'Daily Trigger'
branches:
include:
- main
resources:
pipelines:
- pipeline: MathCalc
source: MathCalc
trigger: none
. . .
The PowerShell script to Call the REST API.
# get-pipleine-run.ps1
$instance = "Server Name"
$collection = "DefaultCollection"
$project = "BrightRanProj"
$pipelineId = 8
$runId = 31
$uri = "https://${instance}/${collection}/${project}/_apis/pipelines/${pipelineId}/runs/${runId}?api-version=7.0"
$pat = "Personal Access Token"
$base64Token = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "", $pat)))
$headers = @{Authorization = "Basic $base64Token"}
$response = Invoke-RestMethod -Method GET -Uri $uri -Headers $headers
$response | ConvertTo-Json -Depth 10 | Out-File -FilePath run-$runId.json