Skip to content

Instantly share code, notes, and snippets.

@aheritier
Created June 3, 2015 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aheritier/5db174d4e37109ca97e9 to your computer and use it in GitHub Desktop.
Save aheritier/5db174d4e37109ca97e9 to your computer and use it in GitHub Desktop.
all-nodes-workspace-cleaner.groovy
/*** BEGIN META {
"name" : "Master Node Workspace Cleaner",
"comment" : "This script will go through all workspaces for any/all jobs on master node and remove them.",
"parameters" : [],
"core": "1.300",
"authors" : [
{ name : "Arnaud Héritier" }
]
} END META**/
import hudson.*;
import hudson.model.*
File jobs = new File(Hudson.getInstance().getRootDir(), "jobs");
File[] dirs = jobs.listFiles(new FileFilter(){
public boolean accept(File f) {
return f.isDirectory();
}
});
if(dirs==null) return;
for (File dir : dirs) {
FilePath ws = new FilePath(new File(dir, "workspace"));
try {
println("Deleting Master workspace : "+ws);
ws.deleteRecursive();
} catch (IOException e) {
println("Failed to delete "+ws);
}
}
for (node in hudson.model.Hudson.instance.nodes)
{
FilePath fp = node.createPath(node.getRootPath().toString() + File.separator + "workspace");
if(fp!=null)
try {
println("Deleting workspace : "+fp+" on node "+node);
fp.deleteRecursive();
} catch (IOException e) {
println("Failed to delete "+fp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment