Skip to content

jenkins-oldbuilds-delete #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions jenkins_delete_old-builds.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
MAX_BUILDS = 10 // max builds to keep

def jobs = Jenkins . instance . items;

for (job in jobs) {
println " Job: " + job . yam
try {
if (job instanceof jenkins.branch.MultiBranchProject ) {
println " Multibranch "
job = job . getJob ( " master " )
}
def recent = job . builds . limit ( MAX_BUILDS )
println " Recent Builds: " + recent
println " ============================= "

for (build in job . builds) {
if ( ! recent . contains (build) && ! build . isBuilding ()) {
println " Deleting: " + build
build . delete ()
println " "
}
}
} catch ( Exception ex) {
continue
}
}