根据时间表部署阶段

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

我正在尝试根据时间表部署其中一个阶段。我已经在 azure-pipelines.yml 文件中定义了 cron 作业。

我有5个阶段。

  1. 构建
  2. 部署测试 - A 国
  3. 部署测试 - B 国
  • 我希望这两个阶段都能在周一至周四晚上获得批准后部署。经批准后不得重复。
  1. 部署到产品 - A 国
  2. 部署到产品 - B 国 这两个阶段是一样的。
schedules:
  - cron: '31 12 * 1-12 1-5'
    displayName: WeekDays
    branches:
      include:
      - AddStage
    always: true
  - cron: '13 20 * 1-12 5-6'
    displayName: Weekend
    branches:
      include:
      - releases/*
    always: true

我设定了乡村赛的条件,但不幸的是我无法达到我想要的:

condition: eq(variables['Build.CronSchedule.DisplayName'], 'WeekDays')
azure azure-devops yaml azure-pipelines-yaml
1个回答
0
投票

根据您的描述,我生成了下面的示例管道。它包含 4 个彼此独立的阶段,每个阶段都有一个

deployment
作业来针对 4 个管道环境运行。

我添加了

Approvals
检查每个环境和每个阶段的不同条件。


trigger: none
schedules:
  - cron: '15 07 * 1-12 1-5' # To be triggered by the tests in my time zone
    displayName: WeekDays
    branches:
      include:
      - AddStage
    always: true
  - cron: '13 20 * 1-12 5-6'
    displayName: Weekend
    branches:
      include:
      - releases/*
    always: true
stages:
- stage: StageTestA
  condition: eq(variables['Build.CronSchedule.DisplayName'], 'WeekDays')
  dependsOn: []
  jobs:
  - deployment: DeploymentTestCountryA
    environment: Env-Test-CountryA
    strategy:
      runOnce:
        deploy:
          steps:
          - script: |
              echo System.StageName is $(System.StageName)
  
- stage: StageTestB
  condition: eq(variables['Build.CronSchedule.DisplayName'], 'WeekDays')
  dependsOn: []
  jobs:
  - deployment: DeploymentTestCountryB
    environment: Env-Test-CountryB
    strategy:
      runOnce:
        deploy:
          steps:
          - script: |
              echo System.StageName is $(System.StageName)
- stage: StageProdA
  condition: eq(variables['Build.CronSchedule.DisplayName'], 'Weekend')
  dependsOn: []
  jobs:
  - deployment: DeploymentProdCountryA
    environment: Env-Prod-CountryA
    strategy:
      runOnce:
        deploy:
          steps:
          - script: |
              echo System.StageName is $(System.StageName)
  
- stage: StageProdB
  condition: eq(variables['Build.CronSchedule.DisplayName'], 'Weekend')
  dependsOn: []
  jobs:
  - deployment: DeploymentProdCountryB
    environment: Env-Prod-CountryB
    strategy:
      runOnce:
        deploy:
          steps:
          - script: |
              echo System.StageName is $(System.StageName)

请注意,要让计划触发器针对某个分支(

AddStage
)工作,我们需要检查
该分支
上的管道引用.yml文件,并确保分支名称为
included

当管道被 cron 计划触发时

Weekdays
,具有条件
eq(variables['Build.CronSchedule.DisplayName'], 'WeekDays')
的阶段将请求批准才能继续, 而条件为
eq(variables['Build.CronSchedule.DisplayName'], 'Weekend')
的两个阶段将被跳过,

顺便说一句,管道环境也支持营业时间检查,您可以考虑将其添加到环境检查中。

如果这不是您的具体场景,请分享您的 YAML 管道的简单结构和其他详细信息,以帮助您了解您的需求。希望信息有帮助。

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