Skip to content

Instantly share code, notes, and snippets.

@TheDauthi
Last active May 15, 2021 09:16
Show Gist options
  • Save TheDauthi/11283199 to your computer and use it in GitHub Desktop.
Save TheDauthi/11283199 to your computer and use it in GitHub Desktop.
Delete all Jenkins builds recursively older than a certain count
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