从另一个管道构建下载工件内容

Download artifact contents from another pipeline build

我有两个 azure devops 管道如下:

这会在第二个管道构建的 $(CustomDestinationFolder) 中创建一个名为 'AncientArtifact-1.2.0.12345' 的文件夹(第一个管道最近的 BuildId=12345)。

我想将上述文件夹重命名为 'ancient' 之类的名称,并将其移动到第二个管道构建中的另一个目录,以包含在第二个管道工件中。

我尝试使用 copy files 任务,但问题是我不知道下载的工件文件夹的名称,因此我只能将其父 $(CustomDestinationFolder) 指定为源文件夹,因此我的目的地文件夹看起来类似于 $(destinationFolder)\AncientArtifact-1.2.0.12345*。 使用 flattenFolders 选项将使所有内容变平,这不是我想要的。

想到了一些方法:

有没有更好的方法来处理这个问题?

您或许可以通过复制文件任务和通配符来获得您想要的东西。

但如果您最终想要重命名工件文件夹以包含在第二个管道中,我会在您下载后继续重命名工件文件夹。

如果它能简单易懂地解决问题,我不会称之为骇人听闻。

- 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'

与 Eric 不同,这里我只是按照您的 idea1 保持工件名称中指定的 $(Build.buildId)

如果你将 pipeline2system.debug 设置为 true,你会看到任务 DownloadBuildArtifacts 本身会根据使用的不同构建生成一个环境变量:BuildNumber

好好利用吧,设置reference name of DownloadBuildArtifacts任务:ref.

然后,您可以在后续步骤中调用此变量以获取 buildid 值:$(ref.BuildNumber)

同时,您可以使用 复制文件 任务,方法是让工件名称中包含 $(Build.BuildId) 值。