我在YAML中有一个用于升级基础结构的管道(我有2个阶段,每个阶段包含一系列作业)
我现在想同时升级多个基础架构,即,将代表部署的标识符列表传递到管道,然后让其分别升级。
这里组织管道的最佳实践是什么?感觉我需要使用循环来生成一组并行作业吗?
据我所知,任何工作失败都会导致完全失败,这可能会使我们处于非常混乱的状态。
答案 0 :(得分:0)
如果您为组织购买了parallel jobs。您可以使用${{each id in parameters.identities}}
,使用Template根据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管道后,可以在执行管道时在参数中输入标识:
然后您将看到多个作业已生成并并行运行:
答案 1 :(得分:0)