This scripts deletes all the tmp files left in workspace-files directory after the build. On windows servers, this seems pretty common so we run this script on daily basis.
import hudson.model.*
def counter = 0
// Create a ref for closure
def delClos
// Define closure
delClos = {
it.eachDir( delClos );
if(it.getName().contains("workspace-files")) {
it.eachFile {
if(it.getName().endsWith(".tmp") ){
println "Deleting file ${it.canonicalPath}";
it.delete()
counter++;
}
}
}
}
// Apply closure
for(item in Hudson.instance.items) {
println "Applying on " + item.rootDir
delClos( item.rootDir )
}
println counter + " files deleted"
Sample ouput produced:
Applying on F:\hudson\.hudson\jobs\job1 Applying on F:\hudson\.hudson\jobs\job2 Applying on F:\hudson\.hudson\jobs\job3 Deleting file F:\hudson\.hudson\jobs\job3\builds\2011-01-31_13-03-47\workspace-files\13a41870.tmp Deleting file F:\hudson\.hudson\jobs\job3\builds\2011-01-31_13-03-47\workspace-files\47d252df.tmp Deleting file F:\hudson\.hudson\jobs\job3\builds\2011-01-31_13-03-47\workspace-files\69ef4579.tmp Applying on F:\hudson\.hudson\jobs\job4 3 files deleted