Skip to content

Instantly share code, notes, and snippets.


Indra Gunawan indrgun

View GitHub Profile
indrgun / cleanupUnusedWorkspaceInSlaves.groovy
Created Oct 4, 2016 — forked from ceilfors/cleanupUnusedWorkspaceInSlaves.groovy
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.
View cleanupUnusedWorkspaceInSlaves.groovy
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) {
indrgun / workspace-purge-simple.groovy
Last active Oct 4, 2016 — forked from rb2k/gist:8372402
A jenkins script to clean up workspaces on slaves
View workspace-purge-simple.groovy
// Check if a slave has < 10 GB of free space, wipe out workspaces if it does
import hudson.model.*;
import hudson.util.*;
import jenkins.model.*;
import hudson.FilePath.FileCallable;
import hudson.slaves.OfflineCause;
import hudson.node_monitors.*;
for (node in Jenkins.instance.nodes) {