Skip to content

Instantly share code, notes, and snippets.

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 bro0k/fec8bb790c327143bcc27e2e3c0ba18d to your computer and use it in GitHub Desktop.
Save bro0k/fec8bb790c327143bcc27e2e3c0ba18d to your computer and use it in GitHub Desktop.
Jenkins - Delete old builds script
MAX_BUILDS = 10 // max builds to keep
def jobs = Jenkins.instance.items;
for (job in jobs) {
println "Job: " + job.name
try {
def recent = job.builds.limit(MAX_BUILDS)
println "Recent Builds: " + recent
println "============================="
for (build in job.builds) {
if (!recent.contains(build) && !build.isBuilding()) {
println "Deleting: " + build
build.delete()
println ""
}
}
} catch(Exception ex) {
continue
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment