Last active
November 2, 2021 12:11
-
-
Save prerak-proof/a72cefd68102da9db59662dc941d451e to your computer and use it in GitHub Desktop.
Jenkins worksplace cleanup
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.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