Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 +
if (isFolder(fullName)) {
deleteUnusedWorkspace(root.child(, "$fullName/")
} else {
if (Jenkins.instance.getItemByFullName(fullName) == null) {
println "Deleting: $fullName "
for (node in Jenkins.instance.nodes) {
println "Processing $node.displayName"
def workspaceRoot = node.rootPath.child("workspace");
deleteUnusedWorkspace(workspaceRoot, "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.