Created
June 3, 2015 19:19
-
-
Save aheritier/5db174d4e37109ca97e9 to your computer and use it in GitHub Desktop.
all-nodes-workspace-cleaner.groovy
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
/*** 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