我们有以下Azure DevOps管道模板:
- stage: DeployToPreprod
displayName: 'Deploy to PREPROD'
dependsOn: PrepareDeployToPreprod
condition: not(eq(variables['Build.Reason'], 'Schedule'))
jobs:
- template: Scripts/deploy.yaml
parameters:
targetHost: SRV-SAF
targetHostDisplayName: SRV_SAF
targetEnv: PREPROD
- template: Scripts/deploy.yaml
parameters:
targetHost: DT1CTX003
targetHostDisplayName: DT1CTX003
targetEnv: PREPROD
- template: Scripts/deploy.yaml
parameters:
targetHost: DT1CTX004
targetHostDisplayName: DT1CTX004
targetEnv: PREPROD
- template: Scripts/deploy.yaml
parameters:
targetHost: VDA-PROD-R01
targetHostDisplayName: VDA_PROD_R01
targetEnv: PREPROD
- template: Scripts/deploy.yaml
parameters:
targetHost: VDA-PROD-R02
targetHostDisplayName: VDA_PROD_R02
targetEnv: PREPROD
- template: Scripts/deploy.yaml
parameters:
targetHost: VDA-PROD-R03
targetHostDisplayName: VDA_PROD_R03
targetEnv: PREPROD
- template: Scripts/deploy.yaml
parameters:
targetHost: VDA-PROD-R04
targetHostDisplayName: VDA_PROD_R04
targetEnv: PREPROD可以很容易地看到,这基本上是用一个不同机器名称的列表实例化相同的模板。是否有一种方法可以删除一些重复,并多次实例化模板,给它一个列表?
发布于 2020-06-09 04:50:51
是否有一种方法可以删除一些重复,并多次实例化模板,给它一个列表?
答案是肯定的。
您可以使用策略与矩阵来解决这个问题:
- stage: DeployToPreprod
displayName: 'Deploy to PREPROD'
dependsOn: PrepareDeployToPreprod
condition: not(eq(variables['Build.Reason'], 'Schedule'))
jobs:
- job: Dev
displayName: Dev
pool:
name: MyPrivateAgent
strategy:
matrix:
dev_1:
targetHost: SRV-SAF
targetHostDisplayName: SRV_SAF
targetEnv: PREPROD
dev_2:
targetHost: DT1CTX003
targetHostDisplayName: DT1CTX003
targetEnv: PREPROD
- template: child.yml #change this to your Scripts/deploy.yaml file
parameters:
targetHost: $(targetHost)
targetHostDisplayName: $(targetHostDisplayName)
targetEnv: $(targetEnv)The Child.yml
parameters:
- name: targetHost
type: string
default: false
- name: targetHostDisplayName
type: string
default: false
- name: targetEnv
type: string
default: false
steps:
- script: echo ${{ parameters.targetHost }}
displayName: 'targetHost'
- script: echo ${{ parameters.targetHostDisplayName }}
displayName: 'targetHostDisplayName'
- script: echo ${{ parameters.targetEnv }}
displayName: 'targetEnv'结果:

希望这能有所帮助。
https://stackoverflow.com/questions/62265525
复制相似问题