Last active
May 15, 2021 09:16
-
-
Save TheDauthi/11283199 to your computer and use it in GitHub Desktop.
Delete all Jenkins builds recursively older than a certain count
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
import hudson.model.* | |
keepCount = 10 | |
// Some plugins - like the CB Folders - don't actually have builds. Filter them | |
jobs = Hudson.instance.getAllItems().findAll { | |
job -> job.hasProperty("lastBuild") | |
} | |
for(job in jobs) | |
{ | |
lastBuildNumber = job.lastBuild.number | |
job.builds.findAll { | |
build -> build.number < lastBuildNumber - keepCount | |
} | |
.each { | |
build -> build.delete() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment