Skip to content

Instantly share code, notes, and snippets.

@ceilfors
ceilfors / cleanupUnusedWorkspaceInSlaves.groovy
Last active September 14, 2023 20:30
When you delete jobs in Jenkins, the corresponding workspaces in the build slaves won't be deleted automatically. This Jenkins script will go to each slave and check if the jobs are already deleted in Jenkins master and delete the workspace.
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) {