You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Azure YAML发布管道中关联预构建工件?

问题:如何在YAML发布管道中关联预构建的冒烟测试工件

我们现有一个按需运行的Azure YAML构建管道,会生成名为smoke的压缩工件;当前通过经典发布管道每周拉取该工件执行冒烟测试。现在计划将发布管道转为YAML格式,需要在新的YAML文件中关联这个预构建的工件。

解决方案

方式1:通过Pipeline资源引用构建工件(推荐)

这种方式可明确关联目标构建管道,还能灵活指定工件版本(比如最新成功版本、特定版本号等),是Azure DevOps YAML发布管道的标准做法。

示例YAML:

# 定义要引用的构建管道资源
resources:
  pipelines:
  - pipeline: SmokeTestBuildPipeline  # 自定义资源名称,后续可用此名称引用
    source: 'Build Smoke Tests'       # 构建管道在Azure DevOps中显示的名称
    trigger: none                     # 设为none,仅手动/每周触发,不随构建完成自动触发
    # 如需指定特定版本,可添加version参数,例如:version: '20240520.1'

stages:
- stage: RunSmokeTests
  displayName: 执行冒烟测试
  jobs:
  - job: SmokeTestJob
    pool:
      vmImage: 'windows-latest'
    steps:
    # 下载关联的构建工件
    - task: DownloadPipelineArtifact@2
      displayName: 下载冒烟测试工件
      inputs:
        buildType: 'specific'
        project: '$(System.TeamProject)'
        pipeline: 'SmokeTestBuildPipeline'  # 对应上面定义的资源名称
        artifactName: 'smoke'               # 构建管道中发布的工件名称
        targetPath: '$(System.ArtifactsDirectory)/smoke-download'

    # 解压工件(与原经典管道步骤一致)
    - task: ExtractFiles@1
      displayName: 解压冒烟测试文件
      inputs:
        archiveFilePatterns: '$(System.ArtifactsDirectory)/smoke-download/SmokeTests.zip'
        destinationFolder: '$(System.ArtifactsDirectory)\smoke'
        overwriteExistingFiles: true

    # 在此添加执行冒烟测试的后续步骤

方式2:直接使用DownloadBuildArtifacts任务下载

如果不需要通过资源管理关联,也可直接在步骤中指定构建管道的名称来下载工件:

示例YAML:

stages:
- stage: RunSmokeTests
  displayName: 执行冒烟测试
  jobs:
  - job: SmokeTestJob
    pool:
      vmImage: 'windows-latest'
    steps:
    - task: DownloadBuildArtifacts@0
      displayName: 下载冒烟测试工件
      inputs:
        buildType: 'current'
        project: '$(System.TeamProject)'
        pipeline: 'Build Smoke Tests'  # 构建管道名称
        buildVersionToDownload: 'latest'
        downloadType: 'single'
        artifactName: 'smoke'
        downloadPath: '$(System.ArtifactsDirectory)'

    # 解压工件
    - task: ExtractFiles@1
      displayName: 解压冒烟测试文件
      inputs:
        archiveFilePatterns: '$(System.ArtifactsDirectory)/smoke/SmokeTests.zip'
        destinationFolder: '$(System.ArtifactsDirectory)\smoke'
        overwriteExistingFiles: true

    # 在此添加执行冒烟测试的后续步骤

关键说明

  • 确保pipeline参数的值和Azure DevOps中构建管道的名称完全一致(比如原经典管道中使用的_Build Smoke Tests,注意空格和大小写)。
  • artifactName必须和构建管道中PublishBuildArtifacts任务指定的$(artifactName)(即smoke)一致。
  • 如需指定特定版本的工件,可在资源配置或下载任务中调整版本参数,比如设置buildVersionToDownload: 'specific'并指定构建ID。

内容的提问来源于stack exchange,提问作者Kev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.11 16:04:59