是否可以克隆 Azure Pipeline? (用于 devops 的元 yaml?)

Is it possible to clone an Azure Pipeline? (meta-yaml for devops?)

我有一个可以在不同的订阅、项目和客户中重复使用的管道。它包含一组适用于基础设施管道代码的各种最佳实践。

AzureDevops 是否有办法导出管道、相关依赖项(资产),并且理想情况下允许在导入时进行参数化替换? (例如项目名称)

只能导出 Azure DevOps 中的经典(UI 模式)管道。

至于yaml管道,它的定义已经在一个代码文件(yml文件)中,这意味着它总是可以被重用。

创建此 yaml 文件后,每次要重用它来创建新管道时,单击 New pipeline - Use the classic editor - Select a source - Choose YAML in Select a template - select yaml 文件路径。

但是,需要注意的一件事是,一旦您在新创建的管道中编辑了 yaml 文件,它将影响使用相同 yaml 文件作为其定义的其他管道,除非您将该文件下载并上传到其他 banrches并在那里创建了新的管道。

为了解决这个问题,Templates也是可以重复使用的yaml文件,它接受的参数可以是"parameterized substitution on import",使用相同模板的不同yaml管道不会影响彼此。

例如模板包含一个参数:

# File: simple-param.yml
parameters:
- name: yesNo # name of the parameter; required
  type: boolean # data type of the parameter; required
  default: false

steps:
- script: echo ${{ parameters.yesNo }}

yaml 管道使用此模板:

# File: azure-pipelines.yml
trigger:
- master

extends:
  template: simple-param.yml
  parameters:
      yesNo: false # set to a non-boolean value to have the build fail