Last active
March 26, 2020 00:07
-
-
Save wknapik/ecc7caf0dc000322cf27c6eab0e6c059 to your computer and use it in GitHub Desktop.
Stagger timed declarative multibranch pipeline executions in Jenkins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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