Created
September 18, 2018 14:22
Star
You must be signed in to star a gist
Clear Jenkins Sandbox Folder from jobs
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
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