Skip to content

Instantly share code, notes, and snippets.

@ryanpadilha
Last active February 23, 2016 11:44
Show Gist options
  • Save ryanpadilha/4a3b5aada28d312bfb3c to your computer and use it in GitHub Desktop.
Save ryanpadilha/4a3b5aada28d312bfb3c to your computer and use it in GitHub Desktop.
Script de limpeza de workspace Jenkins
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