0
votes

I have a build and release pipeline that runs the build stage after every pull request and the release stage on a schedule.

The build stage creates the artifacts and the release stage downloads them.

The problem I have is the download artifact task only seems to work if the current or previous pipeline produced them

E.g.

enter image description here

Should this be possible?

This is what I'm using to publish

- task: PublishPipelineArtifact@1
  inputs:
    targetPath: '$(ArtifactPathToPublish)'
    artifact: '$(ArtifactName)'
    publishLocation: 'pipeline'

And this is what I'm using to download

- task: DownloadPipelineArtifact@2
  inputs:
    buildType: 'specific'
    project: 'a1acfe27-c376-4239-a45c-a77eddf71d6f'
    pipeline: 153
    runVersion: 'latestFromBranch'
    runBranch: $(Build.SourceBranch)
    allowPartiallySucceededBuilds: true
    artifact: '${{ parameters.ArtifactName }}'
    path: '$(Pipeline.Workspace)/${{ parameters.ArtifactName }}'

I can't see any settings that may help with my issue.

At the moment it looks like I would need a hacky fix to find the runId of the last successful pipeline and stage that ran and produced an artifact

1
Hi @Konzy262, How about the issue? Does the answer below resolved your question? If not, would you please let me know the latest information about this issue?Vito Liu
Hi, Just checking in to see whether this issue is still blocking you now? Any update for this issue?Vito Liu
I worked round it by using the REST API to query the build endpoint with a filter on 'individualCI' as the reason filter. I then plugged the id returned into the runId field of the existing Download Pipeline Artifacts task. Your solution looks fine as well although it's more powershell to maintain as you are downloading the artifact manually.Konzy262

1 Answers

1
votes

As a workaround, we can download the specified artifact via the REST API

GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/artifacts?artifactName={artifactName}&api-version=6.1-preview.5

Add task-Power shell and add the below script:

$outfile = "$(System.ArtifactsDirectory)\{artifact name}.zip"
$connectionToken="{pat}"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))

#Get download artifact url
$GetArtifactURL = "GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/artifacts?artifactName={artifactName}&api-version=6.1-preview.5"
$GetArtifactResult = Invoke-RestMethod -Uri $GetArtifactURL -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get 

#download artifact zip file to outfile path
$DownloadArtifactURL = $GetArtifactResult.resource.downloadUrl
$DownloadArtifact = Invoke-RestMethod -Uri $DownloadArtifactURL -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get –OutFile $outfile