Created
September 18, 2018 14:22
-
-
Save O5ten/a59cebf829d9890830e943293f4bcf37 to your computer and use it in GitHub Desktop.
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