1
votes

"Download build artifacts" task has the output variable BuildNumber that makes it possible to get the id of the build the artifact was downloaded from. The new "Download pipeline artifact" task (which is preferred over the "Download build artifacts") does not have any the output variables. Is there a way to get the id of the build the artifact was downloaded from?

Also posted an issue on GitHub.

2

2 Answers

0
votes

There is workaround to get the build id of the downloaded artifact using restful api.

To get the BuildId of the Specific version. You can refer to below below example. First add a powershell task in your pipeline to run below scripts.

To get the definition id provided definition name(definition id will be used in the following scripts), check here for rest API.

$urldefinition ="https://dev.azure.com/<org>/<proj>/_apis/build/definitions?name=AboutSite-ASP.NET-CI&api-version=5.1"

$result = Invoke-RestMethod -Uri $urldefinition -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"} -Method Get
$definition= $result.value
$definitionId = $definition[0].id

Then you can get the build id with below scripts:

$url="https://dev.azure.com/<org>/<proj>/_apis/build/builds?definitions=$definitionId&buildNumber=20191109AboutSite-ASP.NET-CI&statusFilter=completed&resultFilter=succeeded&api-version=5.1"
$result = Invoke-RestMethod -Uri $urldefinition -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"} -Method Get
$build = $result.value
$id = $build[0].id

And then you can output the buildid for the following task to use with below script:

echo "##vso[task.setvariable variable=ArtifactBuildId;isOutput=true]$id"

To get the latest build id you can simply use below api

GET https://dev.azure.com/{organization}/{project}/_apis/build/latest/{definition}?branchName={branchName}&api-version=5.1-preview.1
0
votes

Microsoft is about to release a fix.