Removing old jobs from Jenkins

4,986 views
Skip to first unread message

Alex Brodov

unread,
Sep 18, 2014, 11:05:04 AM9/18/14
to jenkins...@googlegroups.com
I have a lot of jobs in jenkins, i'd like to know how can i shelve them, as far as i know there is a way tu run a script in Jenkins that will do that, for example if i have job 'x' that has 100 builds and job 'y' that has 120 builds and i want to make a rule that will delete all the builds log untill 10, any idea how should i do that ?

Eric Pyle

unread,
Sep 18, 2014, 11:38:40 AM9/18/14
to jenkins...@googlegroups.com
If you want to save only the 10 most recent builds, go into the job configuration and check the "Discard Old Bulds" box, and set "Max # of builds to keep" to 10. Be sure to save your changes. No builds will be deleted until the next time the job is run.

Regards,
Eric


On 9/18/2014 11:05 AM, Alex Brodov wrote:
I have a lot of jobs in jenkins, i'd like to know how can i shelve them, as far as i know there is a way tu run a script in Jenkins that will do that, for example if i have job 'x' that has 100 builds and job 'y' that has 120 builds and i want to make a rule that will delete all the builds log untill 10, any idea how should i do that ?
--
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/d/optout.

Alex Brodov

unread,
Sep 18, 2014, 1:36:37 PM9/18/14
to jenkins...@googlegroups.com
Hi Eric, 
I want to delete in every job the first 10 [1-10] builds but i don't wnat to go over every job (i have more then 150 jobs) and do that, there is any way to do that using a script or  jenkins CLI command or groovy script?
2nd thing is how can i delete a specified range of builds in a specific job with a provided job name


--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/4YoeGZSaDT8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.

Eric Pyle

unread,
Sep 18, 2014, 4:37:59 PM9/18/14
to jenkins...@googlegroups.com
Something like this. For safety, I've written this to print out the list of builds it would delete. Uncomment the delete() line to actually delete builds. As written this would delete the 10 oldest builds of all jobs. If you wanted to delete a specified range of builds of a particular job, it would be a matter of adding a condition of $item.name == "theJob", then use a for loop corresponding to the desired range. You would not need to sort the builds if you know specific build numbers.

Eric

for (item in Hudson.instance.items) {
  builds = item.getBuilds().sort {it.number}
  for (i = 0;i < 10 && i < builds.size();i++) {
    bli = builds[i];
    if (bli != null) {
      b = item.getBuildByNumber(bli.number);
      //if (b != null) {b.delete()}
      if (b != null) {println "Deleting $item.name build # $b.number";}

Alex Brodov

unread,
Sep 18, 2014, 4:56:48 PM9/18/14
to jenkins...@googlegroups.com

Great, I'll try that , do you know where can I find some documentation for thia ?
What packages should import?
Is it based on java ?

Thanks,
Alex

Alex Brodov

unread,
Sep 19, 2014, 6:37:53 PM9/19/14
to jenkins...@googlegroups.com

Do you know where can I find some documentation for this ? 
What packages should i import?


Is it based on java ?

Thanks,
Alex

Alex Brodov

unread,
Sep 19, 2014, 6:39:46 PM9/19/14
to jenkins...@googlegroups.com, eric...@cd-adapco.com

Do you know where can I find some documentation for this ? 
What packages should i import?


Thanks,
Alex

Eric Pyle

unread,
Sep 20, 2014, 1:05:08 PM9/20/14
to Alex Brodov, jenkins...@googlegroups.com
I should mention I tested this in Manage Jenkins/Script Console. If you run it from there you don't need any imports.

Documentation is in the Jenkins Javadoc.

Eric Pyle

unread,
Sep 20, 2014, 1:07:16 PM9/20/14
to Alex Brodov, jenkins...@googlegroups.com
And the language is Groovy.

On 9/19/2014 6:39 PM, Alex Brodov wrote:
Reply all
Reply to author
Forward
0 new messages