-
-
Save mimicscott/214730bcb878acead1f4681731417fba to your computer and use it in GitHub Desktop.
Jenkins - Delete old builds script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAX_BUILDS = 10 // max builds to keep | |
def jobs = Jenkins.instance.items; | |
for (job in jobs) { | |
println "Job: " + job.name | |
try { | |
if(job instanceof jenkins.branch.MultiBranchProject) { | |
println "Multibranch" | |
job = job.getJob("master") | |
} | |
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