AlexandruC
AlexandruC

Reputation: 3637

Download artifact contents from another pipeline build

I have two azure devops pipelines as follows:

This creates a folder named 'AncientArtifact-1.2.0.12345' (first pipeline most recent BuildId=12345) inside a $(CustomDestinationFolder) in the second pipeline build.

I want to rename the above folder to something like 'ancient' and move it to another directory within the second pipeline build to be included in the second pipeline artifact.

I have tried using the copy files task but the problem is I don't know the name of the downloaded artifact folder thus I can only specify its parent $(CustomDestinationFolder) as source folder and so my destination folder will look something like $(destinationFolder)\AncientArtifact-1.2.0.12345*. Using the flattenFolders option will flatten everything and that is not what I want.

Some approaches come to mind:

Is there a better way to handle this?

Upvotes: 1

Views: 4192

Answers (2)

Mengdi Liang
Mengdi Liang

Reputation: 18958

Different with Eric, here I just follow your idea1 by keeping $(Build.buildId) specified in artifact name.

If you set the system.debug of pipeline2 as true, you will see that the task DownloadBuildArtifacts itself generate one environment variable based on different builds used: BuildNumber

enter image description here

Just make use of it, set reference name of DownloadBuildArtifacts task: ref.

Then, you can call this variable to get buildid value during next steps: $(ref.BuildNumber).

Meanwhile, you can use copy files task by keeping the artifact name contain the $(Build.BuildId) value in it.

Upvotes: 0

Eric Smith
Eric Smith

Reputation: 2560

You might be able to do go down a route with the copy file task and wildcards to get what you want.

But if you ultimately want to rename the artifact folder for inclusion in the second pipeline, I would just go ahead rename the artifact folder after you download it.

I would not call it hackish, if it solves the problem simply and is easy to understand.

- task: DownloadBuildArtifacts@0
  inputs:
    buildType: 'specific'
    project: 'your-project'
    pipeline: 'your-pipeline'
    buildVersionToDownload: 'latest'
    downloadType: 'specific'
    downloadPath: '$(System.ArtifactsDirectory)\customLocation'

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: Get-ChildItem $(System.ArtifactsDirectory)\customLocation | Rename-Item -NewName 'ancient'

Upvotes: 1

Related Questions