Skip to content

Instantly share code, notes, and snippets.

@wknapik
Last active March 26, 2020 00:07
Show Gist options
  • Save wknapik/ecc7caf0dc000322cf27c6eab0e6c059 to your computer and use it in GitHub Desktop.
Save wknapik/ecc7caf0dc000322cf27c6eab0e6c059 to your computer and use it in GitHub Desktop.
Stagger timed declarative multibranch pipeline executions in Jenkins
// This generates a consistent, per-branch, not-really-random,
// execution time between 20:00 and 5:59 every day.
branchNum = BRANCH_NAME.inject(0) { acc, c -> acc + ((c as char) as int) }
cronHour = [20, 21, 22, 23, 0, 1, 2, 3, 4, 5][branchNum % 10]
cronMinute = branchNum % 60
cronParams = "${cronMinute} ${cronHour} * * *"
// ...
triggers { cron(cronParams) }
// ...
echo "This pipeline is scheduled to run automatically at ${cronHour}:${cronMinute} every day."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment