Skip to content

Instantly share code, notes, and snippets.

@phaneesh
Created October 16, 2016 02:46
Show Gist options
  • Save phaneesh/428e486fb6782ce555376fedabe2f9b9 to your computer and use it in GitHub Desktop.
Save phaneesh/428e486fb6782ce555376fedabe2f9b9 to your computer and use it in GitHub Desktop.
Cleanup Jenkins
import hudson.model.*
Hudson.instance.items.each {
println(it.name)
def builds = Jenkins.instance.getItemByFullName(it.name).builds
if(builds.size() > 3) {
def toBeDeleted = builds.subList(3, builds.size())
toBeDeleted.each {
println("\t" +it.number)
it.delete()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment