Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save AgrawalAshishS/0e4c2e55328049ca55bc9d25c7b39475 to your computer and use it in GitHub Desktop.

Select an option

Save AgrawalAshishS/0e4c2e55328049ca55bc9d25c7b39475 to your computer and use it in GitHub Desktop.
Delete old Jenkins build from all repositories (including from folder hierarchy)
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