Skip to content

Instantly share code, notes, and snippets.

@marcotc
Created April 22, 2016 20:38
Show Gist options
  • Save marcotc/5a5290f311909be7e14f1c12a23eca97 to your computer and use it in GitHub Desktop.
Save marcotc/5a5290f311909be7e14f1c12a23eca97 to your computer and use it in GitHub Desktop.
Delete builds older then N on Jenkins
MAX_BUILDS = 10
for (job in Jenkins.instance.items) {
println job.name
def recent = job.builds.limit(MAX_BUILDS)
for (build in job.builds) {
if (!recent.contains(build)) {
println "Preparing to delete: " + build
// build.delete()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment