Last active
March 31, 2020 05:20
-
-
Save pmanvi/b00e857afd1e9eedbb9757b75a7ecc06 to your computer and use it in GitHub Desktop.
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
// Lets keep only last 10 builds | |
MAX_BUILDS = 10 | |
def jobs = Jenkins.instance.items; | |
println "Total Jobs" + jobs.size() | |
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 "Cleaning up the build : " + build | |
build.delete() | |
println "Deleted successfully" | |
} | |
} | |
} catch(Exception ex) { | |
println "Neglecting the error" | |
ex.printStackTrace() | |
continue | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment