Skip to content

Instantly share code, notes, and snippets.

@jonesbusy
Created November 21, 2020 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonesbusy/3c198b6a3f72d468d2556151155cee83 to your computer and use it in GitHub Desktop.
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
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