Last active
February 23, 2016 11:44
-
-
Save ryanpadilha/4a3b5aada28d312bfb3c to your computer and use it in GitHub Desktop.
Script de limpeza de workspace Jenkins
This file contains 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 characters
def hi = hudson.model.Hudson.instance | |
hi.getItems(hudson.model.Job).each { | |
job -> | |
jobName = job.getFullDisplayName() | |
if (job.isBuilding()) { | |
println(".. job " + jobName + " is currently running, skipped") | |
return | |
} | |
println(".. wiping out workspaces of job " + jobName) | |
workspacePath = hi.getWorkspaceFor(job) | |
if (workspacePath == null) { | |
println(".... could not get workspace path") | |
return | |
} | |
println(".... workspace = " + workspacePath) | |
pathAsString = workspacePath.getRemote() | |
if (workspacePath.exists()) { | |
workspacePath.deleteRecursive() | |
println(".... deleted from location " + pathAsString) | |
} else { | |
println(".... nothing to delete at " + pathAsString) | |
} | |
job.builds.findAll { it.number != job.lastBuild.number }.each { it.delete() } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment