Created
June 19, 2020 10:25
-
-
Save AgrawalAshishS/0e4c2e55328049ca55bc9d25c7b39475 to your computer and use it in GitHub Desktop.
Delete old Jenkins build from all repositories (including from folder hierarchy)
This file contains hidden or 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 jenkins.model.Jenkins | |
| import hudson.model.Job | |
| MAX_BUILDS = 5 | |
| Jenkins.instance.getAllItems(AbstractItem.class).each { | |
| try{ | |
| println it.fullName | |
| def recent = it.builds.limit(MAX_BUILDS) | |
| for (build in it.builds) { | |
| if (!recent.contains(build)) { | |
| println "Preparing to delete: " + build | |
| build.delete() | |
| } | |
| } | |
| } catch(Exception e) {} | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment