Last active
September 8, 2016 01:46
-
-
Save danilodeveloper/425e83c734c1476e2865 to your computer and use it in GitHub Desktop.
Groovy script - Jenkins - How to keep the last 4 builds and delete the rest
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
hudson.model.Hudson.instance.items.findAll{job -> job.isBuildable() && job.name.contains("stb")}.each{ | |
job -> | |
println("Job : ${job.name}"); | |
builds = jenkins.model.Jenkins.instance.getItem(job.name).getBuilds().reverse(); | |
for(i = 0; i < builds.size() - 4; i++){ | |
builds[i].delete(); | |
println(" Build - ${builds[i]} - Deleted With Success."); | |
} | |
println(" Deleted Builds - ${builds.size()}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment