Last active
January 18, 2020 15:59
-
-
Save jlcrow/22996bfb357c6c57b37cdd908da70da6 to your computer and use it in GitHub Desktop.
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.* | |
import jenkins.model.* | |
import hudson.* | |
import hudson.model.* | |
MAX_BUILDS = 20 | |
for (organization in Jenkins.instance.items) { | |
for (project in organization.items) { | |
int count = 0 | |
String workspace = project.jobsDir | |
File folder = new File(workspace) | |
if(folder!=null && folder.exists()) { | |
for (folders in folder.listFiles()) { | |
File builds = new File(folders.path + "/builds") | |
if (builds!=null && builds.exists()) { | |
File[] files = builds.listFiles().sort() { | |
a,b -> b.lastModified().compareTo a.lastModified() | |
}.each { | |
if(!it.isFile() && it.name.isNumber()) { | |
if(count > MAX_BUILDS) { | |
println it.path + " -- Delete" | |
it.deleteDir() | |
} | |
count++ | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
This script is scary btw - ended up with several paused in flight builds losing their jobs folder during an input hold and then failing afterwards
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Clean out the builds directories to recover space in the Jenkins Home