Last active
March 10, 2020 05:38
-
-
Save phaneesh/d7dbb0854e7a70a517ad29068cf8e9dd to your computer and use it in GitHub Desktop.
Cleanup Old Jenkins builds
This file contains hidden or 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
import jenkins.model.Jenkins | |
import hudson.model.Job | |
MAX_BUILDS = 3 | |
for (job in Jenkins.instance.items) { | |
if(job.name.toLowerCase().endsWith("develop") || job.name.toLowerCase().endsWith("stage")) { | |
println "Deleting old builds: " +job.name | |
def recent = job.builds.limit(MAX_BUILDS) | |
for (build in job.builds) { | |
if (!recent.contains(build)) { | |
build.delete() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment