通过多个作业下载相同的管道工件LatestFromBranch [英] Download same pipeline artifact latestFromBranch over multiple jobs

查看:73
本文介绍了通过多个作业下载相同的管道工件LatestFromBranch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个Azure管道YAML,它可以下载最新的开发工件并在不同的环境中执行不同的测试.

I currently write a Azure pipeline YAML which downloads the latest development artifacts and executes different tests in different environments.

由于每种测试都被建模为自己的作业,因此作业的第一步是下载工件(

Since every kind of test is modeled as its own Job, the first step of the job is downloading the artifact (documentation).

- task: DownloadPipelineArtifact@2
  inputs:
    buildType: 'specific'
    project: '[hidden]'
    definition: '[hidden]'
    buildVersionToDownload: 'latestFromBranch'
    branchName: 'refs/heads/development'

如果在管道运行期间创建了新的产品,我如何实现每个作业都具有相同的工件?

How can I achieve that every job takes the same artifact, also if a newer is created during the pipeline run?

我的第一种方法是下载最新的工件并提取具体版本.但是我无法获得pipelineId所需要的内部版本ID,以下载特定版本.

My first approach was downloading the latest artifact and extracting the concrete version. But I wasn't able to get the build id which is required as pipelineId for downloading a specific version.

推荐答案

我实现了@ LeoLiu-MSFT建议的解决方案.

I implemented a solution as suggested by @LeoLiu-MSFT.

  1. 找到最后一个成功的主版本并存储buildId
  2. buildId作为参数提供下载任务
  3. 在所有测试作业中使用下载任务
  1. Find the last successful master build and store the buildId
  2. Provide a download task with the buildId as parameter
  3. Use the download task in all test jobs

以下摘录显示了一个具体示例.

The following snippets show a concrete example.

# 1. steps/find-latest-build.yml
steps:
  - task: Bash@3
    name: LatestArtifactsBuild
    displayName: 'Find latest successful master build'
    env:
      system_accesstoken: $(System.AccessToken)
    inputs:
      targetType: 'inline'
      script: |
        definitionId=<pipeline>
        url="https://dev.azure.com/<organization>/<project>/_apis/build/builds?api-version=5.1"
        url+="&definitions=$definitionId"
        url+="&resultFilter=succeeded"
        url+="&branchName=refs/heads/master"
        url+="&\$top=1"

        json=$(curl -sL -H "Authorization: Bearer $system_accesstoken" -H 'Content-Type: application/json' $url)
        buildId="$(echo $json | jq '.value[0].id' )"

        echo "##vso[task.setvariable variable=id;isOutput=true]$buildId"

# 2. steps/download-artifacts-from-pipeline-build.yml
parameters:
  definitionId: <pipeline>
  buildId: $(Build.BuildId)
  artifactName: ''

steps:
  - task: DownloadPipelineArtifact@2
    displayName: 'Download build artifact archives'
    inputs:
      buildType: 'specific'
      project: $(System.TeamProjectId)
      definition: ${{ parameters.definitionId }}
      buildVersionToDownload: 'specific'
      pipelineId: ${{ parameters.buildId }}
      artifactName: ${{ parameters.artifactName }}

# 3. examples/reuse-build-artifacts.yml
trigger: none

jobs:
  - job: PrepareBuild
    displayName: 'Provide build information'
    steps:
    - checkout: none
    - template: ../steps/find-latest-build.yml

  - job: DownloadAllArchivesOfSpecificBuild
    dependsOn: PrepareBuild
    variables:
      download_build_id: $[ dependencies.PrepareBuild.outputs['LatestArtifactsBuild.id'] ]
    steps:
    - checkout: none
    - template: ../steps/download-artifacts-from-pipeline-build.yml
      parameters:
        buildId: $(download_build_id)

这篇关于通过多个作业下载相同的管道工件LatestFromBranch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆