Skip to content

Instantly share code, notes, and snippets.

@uurtech
Created February 28, 2020 16:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uurtech/fdf5956f776de6c938d46da880f9f151 to your computer and use it in GitHub Desktop.
Save uurtech/fdf5956f776de6c938d46da880f9f151 to your computer and use it in GitHub Desktop.
Delete Old Builds Jenkins Script
//you can go to Manage Jenkins > Script Console
import jenkins.model.Jenkins
import hudson.model.Job
MAX_BUILDS = 55
Jenkins.instance.getAllItems(Job.class).each { job ->
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