Is there a way to make "discard old builds" happen right now?

1,417 views
Skip to first unread message

jdhein

unread,
Oct 6, 2011, 3:19:55 PM10/6/11
to Jenkins Users
My organization has just tons of projects in Jenkins, many of which
are not active and have not built in some time, some of them haven't
built in over 17 months. I have gone through and turned on "discard
old builds" with a max of 10 builds. However, it has been weeks since
changing this setting and Jenkins has not deleted the excess builds. I
am guessing I have to poke the bear by kicking off a build... only, I
don't want to do this for projects I am not directly involved with.

Is there a way to tell Jenkins to go ahead and discard the old builds
right now?

Christopher Orr

unread,
Oct 7, 2011, 6:11:28 AM10/7/11
to jenkins...@googlegroups.com

You can use the Script Console to fetch the jobs you want, and then call
logRotate() on each of them.

Probably something like this should work, not that I've tested it:

for(job in Hudson.instance.items) {
job.logRotate()
}


Take a look at the examples on the wiki for more info, and if you come
up with something good, you can add it to the list:
https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console

Regards,
Chris

jdhein

unread,
Oct 7, 2011, 6:58:50 PM10/7/11
to Jenkins Users
Thanks, the groovy script you gave me worked like a champ with the
only change I made being to add an import:

import hudson.model.*
for(job in Hudson.instance.items) {
job.logRotate()
}

Honestly, without the groovy script you gave me I would not have been
able to come up with this without investing a bunch of time
researching how Jenkins works and how to write groovy scripts. So
thanks a bunch!

David Vree

unread,
Aug 7, 2013, 12:24:56 AM8/7/13
to jenkins...@googlegroups.com
This worked for me except for one thing.  In a multi-module Maven project the child modules still have all their builds on the filesystem, even though they are gone in the UI.

Richard Bywater

unread,
Aug 7, 2013, 12:42:10 AM8/7/13
to jenkins...@googlegroups.com
Interesting - do they get cleaned up under normal circumstances? (i.e. when a normal discard is done)

Richard.


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Daniel Beck

unread,
Aug 7, 2013, 3:08:54 AM8/7/13
to jenkins...@googlegroups.com
What version of Jenkins are you using?

Ashish Palecha

unread,
Jan 19, 2017, 5:33:38 AM1/19/17
to Jenkins Users
Hey Jdhein,

can u pls provide me whole groovy code what u r using for ur project.
because i am also facing same problem.

lakshmi soma

unread,
Oct 10, 2017, 2:10:04 PM10/10/17
to Jenkins Users
hi can you provide me whole groovy code
Reply all
Reply to author
Forward
0 new messages