Skip to content

Instantly share code, notes, and snippets.

@prerak-proof
Last active November 2, 2021 12:11
Show Gist options
  • Save prerak-proof/a72cefd68102da9db59662dc941d451e to your computer and use it in GitHub Desktop.
Save prerak-proof/a72cefd68102da9db59662dc941d451e to your computer and use it in GitHub Desktop.
Jenkins worksplace cleanup
import hudson.tasks.*
import hudson.plugins.ws_cleanup.*
processGroup(Jenkins.instance)
def processGroup(itemGroup) {
for(item in itemGroup.items) {
if (item.class.simpleName == "Folder") {
processGroup(item)
} else {
hasPreClean = false;
item.buildWrappers.values().each {
if (it instanceof hudson.plugins.ws_cleanup.PreBuildCleanup){
hasPreClean = true;
}
}
if (!hasPreClean) {
println("Adding PreClean to $item.name");
item.getBuildWrappersList().add(new PreBuildCleanup(new ArrayList<Pattern>(), false, "", "", false));
item.save();
}
else {
println("$item.name already has pre-build cleanup enabled");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment