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

Viewed 308

My problem is as follows:

up until now I used Jenkins SCM Polling to check for changes in Production Branches twice a day - but I want to use Azure Devops (on prem 2020) to check for changes, and start a Pipeline if changes occurred, something along those lines:

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

Jenkins had a very practical possibility to SCM Poll over a time`period: cron: 'H H(11-14),H(20-23) * * *' would hash the branch name to have the same branch always SCM poll at the same time(s) for both builds which is practical because starting at the exactly same times presents with issues regarding my resource locking.

(Some resources would be released rather quickly so there would be no waiting if they aren't triggered synchronously)

The only possibility that I see is using Azure Pipelines Expressions due to the fact when they are being resolved.

Is there any possibility to hash some form of inputstring and map it to an array of values?

Do I have to make a feature request for AZP2020 or is there some form of workaround I could use so the develop/support/patch branches can be polled over a two or three hour period?

1 Answers

You can have a try defining multiple schedules with different scheduled times for each branch. So that develop/support/patch branches will be polled over at different time. See below example:

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

Another workaround is to add a server job in the yaml file of support/patch branch to delay the polling of support/patch branch for a fixed time. See below:

Change the azure-pipelines.yml file in support branch like below:

# 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:
   ...
   ...

Change the delay time for patch branch:

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

- job:
  dependsOn: severJob

By adding a server job to delay the execution of pipeline for support/patch branch. The develop/support/patch branches can be polled at different time.

Note: If you want to run your pipeline by only using scheduled triggers, you must disable PR and continuous integration triggers by specifying pr: none and trigger: none in your YAML file

Related