0
votes

In the release pipeline, I've a job which fetches multiple artifacts (previously built in Devops), listed here as A and B.

enter image description here

As a first step, I need to get the list of the artifact's name used in the current release. For this, I have some Powershell script that returns this.

Based on the API doc (https://docs.microsoft.com/en-us/rest/api/azure/devops/release/releases/get%20release?view=azure-devops-server-rest-5.0#artifact) it's supposed to return such info (version.id)

$url = "<project URL>/_apis/release/releases/" + $releaseid + "?api-version=5.1"
$res = Invoke-RestMethod -Uri $url -Method Get -Headers @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" } 

foreach ($a in $res.artifacts)
{
  Write-Host "Artifact name: "$a.alias
  Write-Host "Artifact version: "$a.version.id
}

This returns nothing in the version field:

Artifact name:  test-scripts
Artifact version:  
Artifact name:  A
Artifact version:  
Artifact name:  B
Artifact version:

Any pointer on this much appreciated.

1

1 Answers

1
votes

You need to point to definitionReference.version.id instead of version.id.

Working Code snippet:

$PATToken = "####"
$AuthHeader= @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PATToken)")) }

$url = "https://vsrm.dev.azure.com/{organization}/${project}/_apis/release/releases/{release id}?api-version=5.1"
$res = Invoke-RestMethod -Uri $url -Method get -Headers $AuthHeader


foreach ($a in $res.artifacts)
{
  Write-Host "Artifact name: "$a.alias
  Write-Host "Artifact version: "$a.definitionReference.version.id
}

Output:

enter image description here

Verification:

enter image description here