Azure Pipeline Cron Scheduler:不要 SCM 在同一时间轮询所有分支

Azure Pipeline Cron Scheduler: dont SCM Poll all branches at exactly the same time

我的问题如下:

到目前为止,我每天两次使用 Jenkins SCM 轮询来检查生产分支中的更改 - 但我想使用 Azure Devops(在 2020 年 prem 上)来检查更改,并在发生更改时启动管道,一些东西按照这些思路:

schedules:
- cron: '5 13/12 * * *' # cron syntax defining a schedule in UTC time
  displayName: 'Automatic Deployment'
  branches:
    include:
      - develop
      - support
      - patch
  always: false

Jenkins 在一段时间内对 SCM 轮询有非常实际的可能性: cron: 'H H(11-14),H(20-23) * * *' 会对分支名称进行哈希处理,使相同的分支始终在同一时间对两个构建进行 SCM 轮询,这很实用,因为在完全相同的时间开始会出现有关我的资源锁定的问题。

(有些资源会很快释放,不同步触发就不会等待)

我看到的唯一可能性是使用 Azure Pipelines Expressions,因为它们正在被解决。

是否有可能散列某种形式的输入字符串并将其映射到值数组?

我是否必须为 AZP2020 提出功能请求,或者我是否可以使用某种形式的解决方法,以便可以在两三个小时内轮询 develop/support/patch 个分支?

您可以尝试为每个分支定义多个具有不同计划时间的计划。这样 develop/support/patch 个分支将在不同的时间被轮询。请参阅以下示例:

schedules:
- cron: '5 13/12 * * *' # cron syntax defining a schedule in UTC time
  displayName: 'Automatic Deployment'
  branches:
    include:
      - develop
  always: false

- cron: '5 15/12 * * *' # cron syntax defining a schedule in UTC time
  displayName: 'Automatic Deployment'
  branches:
    include:
      - support
  always: false

- cron: '5 17/12 * * *' # cron syntax defining a schedule in UTC time
  displayName: 'Automatic Deployment'
  branches:
    include:
      - patch
  always: false

另一种解决方法是在support/patch分支的yaml文件中添加一个server job来延迟对support/patch分支的轮询固定时间。见下文:

更改支持分支中的 azure-pipelines.yml 文件,如下所示:

# azure-pipelines.yml @ support branch

schedules:
- cron: '5 13/12 * * *' # cron syntax defining a schedule in UTC time
  displayName: 'Automatic Deployment'
  branches:
    include:
      - develop
      - support
      - patch
  always: false

jobs:
- job: severJob
  pool: server
  steps:
 
  - task: Delay@1
    inputs:
      delayForMinutes: '120'
      
- job:
  dependsOn: severJob
  pool: 
    vmImage: windows-latest
  steps:
   ...
   ...

更改补丁分支的延迟时间:

# azure-pipelines.yml @ patch branch
schedules:
...
jobs:
- job: severJob
  pool: server
  steps:
 
  - task: Delay@1
    inputs:
      delayForMinutes: '240'

- job:
  dependsOn: severJob

通过添加服务器作业来延迟 support/patch 分支的管道执行。 develop/support/patch 个分支可以在不同的时间轮询。

注意:如果您想 运行 您的管道仅使用计划触发器,您必须通过指定 pr: nonetrigger: none 在您的 YAML 文件中