Last active
September 17, 2019 15:23
-
-
Save serbixote/4b08ee459adc008d59a7bae7c2f1b82e to your computer and use it in GitHub Desktop.
Delete old builds from all configured Jobs in Jenkins, in a selective way.
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 | |
int MAX_BUILDS_TO_KEEP = 5 | |
Jenkins.instance.getAllItems(Job.class).each { job -> | |
job.builds.drop(MAX_BUILDS_TO_KEEP).findAll { | |
!it.keepLog && | |
!it.building && | |
it != job.lastStableBuild && | |
it != job.lastSuccessfulBuild && | |
it != job.lastUnstableBuild && | |
it != job.lastUnsuccessfulBuild | |
}.each { build -> | |
build.delete() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment