Forked from ceilfors/cleanupUnusedWorkspaceInSlaves.groovy
Created
October 4, 2016 18:44
-
-
Save indrgun/4312429bdfbbef067740036666743f55 to your computer and use it in GitHub Desktop.
Revisions
-
ceilfors revised this gist
Sep 9, 2015 . No changes.There are no files selected for viewing
-
ceilfors revised this gist
Aug 27, 2015 . No changes.There are no files selected for viewing
-
ceilfors revised this gist
Aug 27, 2015 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,19 +10,19 @@ def boolean isFolder(String name) { def deleteUnusedWorkspace(FilePath root, String path) { root.list().each { child -> String fullName = path + child.name if (isFolder(fullName)) { deleteUnusedWorkspace(root.child(child.name), "$fullName/") } else { if (Jenkins.instance.getItemByFullName(fullName) == null) { println "Deleting: $fullName " child.deleteRecursive() } } } } for (node in Jenkins.instance.nodes) { println "Processing $node.displayName" def workspaceRoot = node.rootPath.child("workspace"); deleteUnusedWorkspace(workspaceRoot, "") } -
ceilfors created this gist
Aug 27, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ import com.cloudbees.hudson.plugins.folder.Folder import hudson.FilePath import jenkins.model.Jenkins def boolean isFolder(String name) { def item = Jenkins.instance.getItemByFullName(name) return item instanceof Folder } def deleteUnusedWorkspace(FilePath root, String path) { root.list().each { child -> String fullName = path + child.name if (isFolder(path + child.name)) { deleteUnusedWorkspace(root.child(child.name), path + "$child.name/") } else { if (Jenkins.instance.getItemByFullName(fullName) == null) { println "Deleting unused workspace $fullName " child.deleteRecursive() } } } } for (node in Jenkins.instance.nodes) { println node.displayName def workspaceRoot = node.rootPath.child("workspace"); deleteUnusedWorkspace(workspaceRoot, "") }