Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clear Jenkins Sandbox Folder from jobs
import hudson.model.*
def isFolder = { it.class.canonicalName == 'com.cloudbees.hudson.plugins.folder.Folder' }
def isSandbox = { "sandbox" == it.fullName }
def deleteChildren = {
it.getItems().collect { item ->
def deletedName = item.fullName
item.delete()
"${deletedName} deleted"
}
}
def findAndClearSandbox = { allJobs ->
["\nJobs found and removed in sandbox",
"==================================",
allJobs.findAll(isFolder)
.findAll(isSandbox)
.collect(deleteChildren)
.flatten()
.join('\n') ?: 'Nobody has been using the sandbox this week. :(',
"=================================="].join('\n')
}
findAndClearSandbox(Hudson.instance.items)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment