动态构建模板参数

问题描述 投票:0回答:1

我需要扩展某个管道模板,它需要这样的参数:

  parameters:
    deploy_stages: 
    - DEV
    - PROD

是否可以根据环境变量动态构建这些模板参数:

trigger:
  batch: true

resources:
  repositories:
  - repository: templates
    type: git
    ref: refs/heads/master
    name: my-template

variables:
- group: deployment-branches

extends:
  template: my-template.yml@templates
  parameters:
    deploy_stages: $(deployment)

steps:
  - bash: |
      DEPLOY_STAGES=( $deployment-branches.DEV, deployment-branches.PROD)
      echo "those are the stages: $DEPLOY_STAGES"
      echo "##vso[task.setvariable variable=deployment]$DEPLOY_STAGES"
azure-pipelines
1个回答
0
投票

使用变量:

extends:
  template: my-template.yml@templates
  parameters:
    deploy_stages:
      - $(stageA)
      - $(stageB)

上面的摘录假设变量

$(stageA)
$(stageB)
是在管道中的某处或通过变量组声明或定义的。

使用管道参数:

# my-pipeline.yaml

parameters:
  - name: stages
    displayName: 'Stages to deploy'
    type: object
    default:
      - DEV
      - PROD
    
  # ...

  extends:
    template: my-template.yml@templates
    parameters:
      deploy_stages: ${{ parameters.stages }}

在这种情况下,您可以直接从管道参数

deploy_stages
设置
stages

© www.soinside.com 2019 - 2024. All rights reserved.