Azure Pipelines - 计划管道的最佳实践?

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

我有一个 ci/cd YAML 管道用于部署我的 Kubernetes 集群。我还有一个单独的 YAML 管道,用于扩大和缩小集群规模。

我的放大和缩小 YAML 检索每个环境的当前部署构建,因为我们的存储库只有一个主分支。这确保我们不会部署任何尚未部署到环境(开发、阶段和产品)的新 helm 值。

我应该继续保留单独的 YAML 文件还是将其压缩到单个管道中?有没有最佳实践或者这真的取决于团队的偏好?

azure-devops azure-pipelines devops kubernetes-helm cicd
1个回答
0
投票

我应该继续保留单独的 YAML 文件还是将其压缩到单个管道中?

简短回答:到处使用模板

更多详情

使用模板隐藏复杂的实现细节,并在管道内或跨管道重用逻辑和配置。

逻辑(又名功能)模板:

  • 步骤:定义一系列可以跨作业重用的步骤,或在另一个步骤模板中引用。- 作业:定义可以跨阶段或管道重用的一个或多个作业。
  • 阶段:定义一个或多个可以跨管道重用的阶段。

配置模板:

  • 变量:定义一组可以跨作业、阶段或管道重用的变量。

示例:

variables:
  - template: /pipelines/variables/common-variables.yaml

pool: 
  name: $(agentPool)

stages:
  - stage: Build
    displayName: Build and publish Docker image
    jobs:
      - job: BuildAndPushDocker
        displayName: Build and push Docker image
        variables:
          - template: /pipelines/variables/docker-variables.yaml
        steps:
          - checkout: self
          - template: /pipelines/steps/build-push-docker-steps.yaml
            parameters:
              workingDirectory: $(workingDirectory)
              # ...

  - stage: DeployDev
    displayName: Deploy to Dev
    dependsOn: Build
    jobs:
      - job: DeployDev
        displayName: Deploy to Dev
        variables:
          # reference environment-specific variables here
          - template: /pipelines/variables/dev-variables.yaml
        steps:
          - checkout: self
          - template: /pipelines/steps/deploy-helm-chart-steps.yaml
            parameters:
              # use variables from /pipelines/variables/dev-variables.yaml
              chart: $(chart)
              namespace: $(namespace)
              valuesFile: $(valuesFile)
              # ...

  - stage: DeployStage
    displayName: Deploy to Stage
    dependsOn: DeployDev
    jobs:
      - job: DeployStage
        displayName: Deploy to Stage
        variables:
          # reference environment-specific variables here
          - template: /pipelines/variables/stage-variables.yaml
        steps:
          - checkout: self
          - template: /pipelines/steps/deploy-helm-chart-steps.yaml
            parameters:
              # use variables from /pipelines/variables/stage-variables.yaml
              chart: $(chart)
              namespace: $(namespace)
              valuesFile: $(valuesFile)
              # ...

  - stage: DeployProd
    displayName: Deploy to Prod
    dependsOn: DeployStage
    jobs:
      - job: DeployProd
        displayName: Deploy to Prod
        variables:
          # reference environment-specific variables here
          - template: /pipelines/variables/prod-variables.yaml
        steps:
          - checkout: self
          - template: /pipelines/steps/deploy-helm-chart-steps.yaml
            parameters:
              # use variables from /pipelines/variables/prod-variables.yaml
              chart: $(chart)
              namespace: $(namespace)
              valuesFile: $(valuesFile)
              # ...

上述管道使用步骤和变量模板,使我们能够重用功能,例如部署 Helm 图表,为每个环境使用不同的配置。

也可以创建作业或阶段的模板。

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