ADO 任务下载与 DownloadPipelineArtifact@2

ADO task download vs DownloadPipelineArtifact@2

提问人:Herbert 提问时间:10/7/2023 更新时间:10/8/2023 访问量:68

问:

我正在设置一个需要由另一个生成管道触发的生成作业。

trigger:
- main

resources:
  pipelines:
  - pipeline: triggeredpipeline # Name of the pipeline resource.
    source: <pipeline path and name> # The name of the pipeline referenced by this pipeline resource.
    project: <ADO project name> # Required only if the source pipeline is in another project
    trigger: true # Run app-ci pipeline when any run of security-lib-ci completes

pool: Default

下一步是从触发作业中获取工件,以在触发的生成作业中执行魔术。

现在,我遇到了这样的情况:ADO“下载”(https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/steps-download?view=azure-pipelines)允许我重用管道引用,但不允许我显式指定目标位置。

  - download: triggeredpipeline  # pipeline resource identifier.
    displayName: Download files from triggering pipeline
    artifact: Platform

如文档中所述,它会将其写入 ,例如 /triggeredpipeline/Platform(或 Platform 中的内容)$(Pipeline.Workspace)/<pipeline resource identifier>/<artifact name>

现在文档指出这是 DownloadPipelineArtifact@2 的简写,根据该文档 (https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/download-pipeline-artifact-v2?view=azure-pipelines),可以指定 .我没有看到/了解如何重用我的管道引用。我只能设置触发构建的项目和管道的 ID。downloadtargetPath

- task: DownloadPipelineArtifact@2
  inputs:
    buildType: 'specific'
    project: '<uuid>'
    definition: '266'
    buildVersionToDownload: 'latest'
    artifactName: 'Platform'
    targetPath: '$(Build.ArtifactStagingDirectory)'

那么我如何使用对触发器( )的引用,但仍然能够定义目标文件夹是什么。pipeline: triggeredpipeline

(是的,我可以添加一些执行复制的任务,但是源工件的大小相当大,因此下载,然后再次移动/复制它是浪费时间)

我希望你们中的一个人以前使用过触发式构建管道,并且知道一种重用触发器引用的方法,以便一次性将工件下载到正确的位置。

azure-devops download ado azure-pipelines-yaml

评论


答:

0赞 Daniel Mann 10/7/2023 #1

你正在寻找旗帜。specificBuildWithTriggering

从文档中:

别名:preferTriggeringPipeline。自选。当 source == 特定时使用。在适当的情况下,从触发生成下载项目。

评论

0赞 Herbert 10/7/2023
但这仍然需要指定项目名称。
0赞 Herbert 10/7/2023
此 ''' - 任务:DownloadPipelineArtifact@2 displayName:从触发管道输入下载文件:buildType: 'specific' specificBuildWithTriggering: true artifactName: 'Platform' targetPath: '$(Build.ArtifactStagingDirectory)' '''
0赞 Herbert 10/7/2023
导致此错误 ''' ##[debug]TargetPath: C:\fgrbuildagent1_work\1009\a ##[debug]ArtifactName: Platform ##[debug]BuildResult: Succeeded ##[debug]Run: Specific ##[error]Project Name (Parameter 'notFound:CannotBeNullOrEmpty') ##[debug]Processed: ##vso[task.logissue type=error;]项目名称(参数 'notFound:CannotBeNullOrEmpty') ##[debug]Processed: ##vso[task.complete result=Failed;] '''
1赞 Krzysztof Madej 10/8/2023 #2

您可以使用此处列出的元数据

resources.pipeline.<Alias>.projectName
resources.pipeline.<Alias>.projectID
resources.pipeline.<Alias>.pipelineName
resources.pipeline.<Alias>.pipelineID
resources.pipeline.<Alias>.runName
resources.pipeline.<Alias>.runID
resources.pipeline.<Alias>.runURI
resources.pipeline.<Alias>.sourceBranch
resources.pipeline.<Alias>.sourceCommit
resources.pipeline.<Alias>.sourceProvider
resources.pipeline.<Alias>.requestedFor
resources.pipeline.<Alias>.requestedForID

并将它们与DownloadPipelineArtifact@2

  - task: DownloadPipelineArtifact@2
    inputs:
      buildType: 'specific'
      project: '$(resources.pipeline.triggeredpipeline.projectID)'
      definition: '$(resources.pipeline.triggeredpipeline.pipelineID)'
      specificBuildWithTriggering: true
      buildVersionToDownload: 'specific'
      pipelineId: '$(resources.pipeline.triggeredpipeline.runID)'
      artifactName: 'Platform'
      targetPath: '$(Build.ArtifactStagingDirectory)'

评论

0赞 Herbert 10/8/2023
感谢两位的澄清