azure - 集中管理的 Azure 管道

标签 azure azure-devops azure-pipelines azure-pipelines-release-pipeline

我正在开发一个 ADO 项目,该项目当前有 100 多个存储库,每个存储库都包含完全相同的管道,该管道定义了时间表并指向另一个包含要使用的模板的存储库。不幸的是,现在是对管道的时间表和结构进行一些更改的时候了(以前是作业模板,现在是阶段)。

正如你所想象的,我真的不想通过 100 多个存储库来进行更改。如果真的有必要,我不想再这样做了。

因此我的问题是,是否可以集中管理这些管道?即,我有一个包含所有 yml 文件的存储库,那么当我想为新存储库创建管道时,我可以指向该 yaml 存储库吗?

干杯,

美联社

最佳答案

您可以使用 extends 构造将完整的管道定义放入公共(public)存储库中,然后仅公开每个存储库必须配置的参数(如果有)。

来自documentation of templates

Templates let you define reusable content, logic, and parameters. Templates function in two ways. You can insert reusable content with a template or you can use a template to control what is allowed in a pipeline.

If a template is used to include content, it functions like an include directive in many programming languages. Content from one file is inserted into another file. When a template controls what is allowed in a pipeline, the template defines logic that another file must follow.

听起来您到目前为止一直在使用 include 指令等模板,而是按照 Security through templates 中所述扩展模板。您基本上可以将管道的完整定义(包括作业和阶段)放在模板中:

Azure Pipelines offers two kinds of templates: includes and extends. Included templates behave like #include in C++: it's as if you paste the template's code right into the outer file, which references it. To continue the C++ metaphor, extends templates are more like inheritance: the template provides the outer structure of the pipeline and a set of places where the template consumer can make targeted alterations.

示例:

# File: pipeline.yaml
# Repo: templaterepo
parameters:
- name: CustomProperty
  type: String

stages:
- stage: A
  jobs:
  - job: A1
    pool:
      vmImage: 'ubuntu-16.04'
    steps:
      - script: echo "Custom property is ${{ parameters.CustomProperty}}"

# File: azure-pipelines.yml, placed in each of you 100 repos
# Repo: myapp

resources:
  repositories:
    - repository: templates
      type: git
      name: templaterepo

trigger:
- master

extends:
  template: pipeline.yml@templates
  parameters:
      CustomProperty: "Hello World"

如果配置选项的数量保持在最低限度,那么这 100 个存储库中的每个文件都可以大部分是静态的。通过referencing a branch相反,存储库中包含公共(public)管道的标记(例如创建的 master/main 新管道将始终获取该分支上的最新管道定义,从而减少了中央管道将其推送到正确的分支。

关于azure - 集中管理的 Azure 管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65814579/

相关文章:

azure - Cloud Foundry 中是否可以实现虚拟机级别(单元级别)的自动扩展?如果是,如何实现这一目标?

azure - DocumentDB 能否成功充当包含数据和逻辑的整个移动应用程序后端

azure - 在Azure Web应用程序中运行docker容器: didn't respond to HTTP pings on port

Selenium 测试有时会因 azure 管道而失败并在本地通过

azure - 如何以编程方式获取当前的 Azure Devops 管道对象 ID 以授予对 Azure 资源的访问权限

c# - .net Core Controller Action ,返回静态html页面

azure-devops - 如何在 AzureDevOps Pipeline VSTest@2 中定义多个匹配模式?

asp.net - 如何为Azure数据库设置正确的连接字符串?

azure-devops - 有条件地在 azure 管道中使用变量组

git - 将 Azure DevOps 连接到内部 IP 存储库