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 <http://javadoc.jenkins-ci.org>.


On 9/19/2014 6:39 PM, Alex Brodov wrote:

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


Thanks,
Alex

On Sep 18, 2014 11:37 PM, "Eric Pyle" <eric.p...@cd-adapco.com <mailto:eric.p...@cd-adapco.com>> wrote:

    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 <http://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
    <http://item.name> build # $b.number";}
        }
      }
    }

    On 9/18/2014 1:36 PM, Alex Brodov wrote:
    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


    On Thu, Sep 18, 2014 at 6:23 PM, Eric Pyle
    <eric.p...@cd-adapco.com <mailto:eric.p...@cd-adapco.com>> wrote:

        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-users+unsubscr...@googlegroups.com
        <mailto:jenkinsci-users+unsubscr...@googlegroups.com>.
        For more options, visit https://groups.google.com/d/optout.

-- 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-users+unsubscr...@googlegroups.com
        <mailto:jenkinsci-users+unsubscr...@googlegroups.com>.
        For more options, visit https://groups.google.com/d/optout.


-- 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-users+unsubscr...@googlegroups.com
    <mailto:jenkinsci-users+unsubscr...@googlegroups.com>.
    For more options, visit https://groups.google.com/d/optout.

-- 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-users+unsubscr...@googlegroups.com
    <mailto:jenkinsci-users+unsubscr...@googlegroups.com>.
    For more options, visit https://groups.google.com/d/optout.


--
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-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to