Created
November 21, 2020 13:49
-
-
Save jonesbusy/3c198b6a3f72d468d2556151155cee83 to your computer and use it in GitHub Desktop.
Ensure to align all next build number. Useful when restoring build history when job are recreated
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
jenkins.model.Jenkins.instance.allItems.findAll { (it instanceof hudson.model.Job) }.each { item -> | |
def nextBuildNumber = item.getNextBuildNumber() | |
def build = item.getLastBuild() | |
if (build != null) { | |
def lastBuildNumber = build.getNumber() | |
if (nextBuildNumber <= lastBuildNumber) { | |
println("Detected previous build number '${nextBuildNumber}' is smaller than last build '${lastBuildNumber}' for job '${item.displayName}'.") | |
nextBuildNumber = lastBuildNumber + 1 | |
println("Performed update to '${nextBuildNumber}'") | |
item.updateNextBuildNumber(nextBuildNumber) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment