【问题标题】:Parallelisation of Azure PipelinesAzure 管道的并行化
【发布时间】:2020-07-21 14:12:19
【问题描述】:

我有一个升级基础设施的管道(在 YAML 中)(我有 2 个阶段,每个阶段包含一系列作业)

我现在想同时升级多个基础架构,即将代表部署的标识符列表传递给管道,然后让它升级每个。

组织管道的最佳做法是什么?感觉我需要使用循环生成一组并行作业?

据我了解,任何工作失败都会导致彻底失败,这可能会使我们处于非常困惑的状态。

【问题讨论】:

  • 您是否使用过这个(我假设您将我引向矩阵),其中输入是动态设置的,即我传入一组基础设施身份 1、2、3、50 来表示我要更新的基础设施?
  • 如何在您的管道中动态设置基础架构身份?你是在第一阶段设置身份,然后将身份传递给第二阶段进行升级吗?
  • 执行管道的人会将它们作为参数输入
  • 嗨,您有机会试用下面的模板吗,效果如何?

标签: azure azure-pipelines


【解决方案1】:

如果您为您的组织购买了parallel jobs。您可以使用Template 使用表达式${{each id in parameters.identities}} 根据身份参数生成多个作业。

因此,您可以将升级基础架构的作业移动到模板中,并如下定义您的 yaml 管道。见下例:

模板文件:upgrade-infrastructure.yml

parameters:
  id: 1
  
jobs:
- job: upgradeinfra${{parameters.id}}

  steps:
  - powershell: echo "upgrade-infra-${{parameters.id}}"

azure-pipelines.yml

#define the identities as a object to hold a array object of ids
parameters:
- name: identities 
  type: object
  default:
    ids:
    - 1
    - 2


trigger: none

stages:
- stage: Upgrage
  pool: 
    vmImage: windows-latest
  
  jobs:
  - job: A
    steps:
    - powershell: echo "job A"    
  
  #loop through the ids array object and the each id to the template paramter to generate multiple jobs for each id.
  #indentation is very important, bad indentation may cause pipeline compile error.
  - ${{ each id in parameters.identities.ids }}:
    - template: upgrade-infrastructure.yml
      parameters: 
        id: ${{id}}

如上设置好你的yaml管道后,你可以在执行管道时在参数中输入身份:

然后你会看到多个作业被生成并并行运行:

【讨论】:

    【解决方案2】:

    要使您的部署并行运行,您需要做的就是设置依赖项。 (对上一步的依赖是自动设置的)。这是一个阶段的示例,该阶段仅依赖于构建,然后所有阶段将并行运行:

    stage:
       -stages : DeployTo${{ parameters.environment }}
         dependsOn: ["Build"] //The stage that build the code is called "Build"
       
    

    结果如下所示:

    如果没有 dependsOn 属性,您的管道阶段将按顺序运行,如下所示:

    stages:
       -stage : DeployTo${{ parameters.environment }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      • 2020-05-29
      • 1970-01-01
      • 1970-01-01
      • 2020-10-05
      • 2021-11-13
      相关资源
      最近更新 更多