Search code examples
azureazure-devopsazure-devops-extensions

Download artifact contents from another pipeline build


I have two azure devops pipelines as follows:

  • the first one creates an artifact under the name 'AncientArtifact-1.2.0.$(Build.BuildId)'.
  • the second one is trying to use this artifact using the Download Build Artifacts task configured as follows: enter image description here

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:

  • Remove the $(Build.BuildId) from the artifact name. This way I know the exact name that the downloaded artifact will have. The issue is that I would like to keep it.
  • A custom script in the second pipeline that would list the folders inside the $(CustomDestinationFolder), get the name of the artifact folder rename it a hardcoded 'ancient' name. It feels quite hackish.

Is there a better way to handle this?


Solution

  • 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.