Skip to content

Instantly share code, notes, and snippets.

@mdutkin
Last active October 11, 2019 22:32
Show Gist options
  • Save mdutkin/feb236d34bea14052ac1cf7d772da43f to your computer and use it in GitHub Desktop.
Save mdutkin/feb236d34bea14052ac1cf7d772da43f to your computer and use it in GitHub Desktop.
Jenkins delete old build for job via Script Console
import jenkins.model.Jenkins
import hudson.model.Job
MAX_BUILDS = 5
Jenkins.instance.getAllItems(Job.class).each { job ->
if (job.fullName == 'DatabaseDocker/master') {
println job.fullName
def recent = job.builds.limit(MAX_BUILDS)
for (build in job.builds) {
if (!recent.contains(build)) {
println "Preparing to delete: " + build
// build.delete()
}
}
}
}
println "============= DONE ============="
@mdutkin
Copy link
Author

mdutkin commented Jul 2, 2019

if you want to REALLY delete your build - uncomment // build.delete() line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment