【问题标题】:Using templates to pass paramters in an Azure Devops 2020 yaml pipeline使用模板在 Azure Devops 2020 yaml 管道中传递参数
【发布时间】:2021-02-03 20:15:47
【问题描述】:

我想实现一个 yaml 管道,这样我可以一次设置某些解决方案参数,然后在多个管道中使用它。目前我有:

azure-pipelines.yml

trigger:
- master

name: $(BuildVersionPrefix).$(DayOfYear)$(Date:HH)

extends:
  parameters:
    buildTemplate: build.yml
  template: solutions.yml

solutions.yml

parameters:
  - name: buildTemplate
    type: string
    default: ""

extends:
  template: ${{parameters.buildTemplate}}
  parameters:
    solutions: 
      - name: a
        SomeOtherProperty: x
      - name: b
        SomeOtherProperty: y
      - name: c
        SomeOtherProperty: z
      - name: d
        SomeOtherProperty: u
      - name: e
        SomeOtherProperty: v

build.yml

parameters:
  - name: solutions
    type: object
    default: []

steps:
 - ${{ each solution in parameters.solutions}}:
    - script: echo ${{solution.name}}
      displayName: build ${{solution.name}}

使用此配置,我需要每个管道有两个 yml 文件,一个可以跨多个管道共享。有没有办法让每个管道有一个 yml 文件,同时将解决方案抽象到一个共享文件中?

编辑 1

为了强调我们需要完整的语法来解决我添加的具有不同值的SomeOtherProperty

【问题讨论】:

  • 嗨@silvermeru。这张票有更新吗?如果答案能给你一些帮助,请随时告诉我。只是提醒this

标签: azure-devops azure-pipelines azure-yaml-pipelines


【解决方案1】:

有没有办法让每个管道有一个 yml 文件,同时将解决方案抽象到一个共享文件中?

您可以尝试以下示例:

BuildandSolution.yml:

parameters:
  - name: solutions
    type: object
    default: [a,b,c,d,e]

steps:
- ${{ each solution in parameters.solutions }}: 
    - script: echo ${{ solution }}
      displayName: build ${{ solution }}

Azure-Pipelines.yml:

trigger:
- none

pool:
  vmImage: 'ubuntu-latest'

steps:
  - template: buildandsolution.yml

您可以直接将值添加到解决方案参数(对象类型)。

更新:

我能理解您的要求,但恐怕我们无法与构建步骤分开指定解决方案参数。

以下是两个区块:

1.定义参数时不能直接使用对象类型参数的定义格式:

solutions: 
  - name: a
    SomeOtherProperty: x

这种定义方法需要依赖另一个模板。

2.我们不能只在模板中定义参数而不添加任何构建步骤。

此方法仅受变量支持。

参数字段不能调用yaml中的参数模板。因此,如果只定义纯参数,则无法在主yaml中调用。

【讨论】:

  • 道歉我应该更清楚。我想与构建步骤分开指定解决方案参数。例如,这样我就可以为 PR 和 CI 构建使用同一组解决方案
  • 嗨@silvermeru。感谢您的澄清。恐怕没有办法能满足你的要求。您可以参考我的更新中的信息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-29
  • 2020-03-15
  • 2021-08-29
  • 2020-05-28
  • 2022-06-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多