Recommending for cleaning up old builds when multibranch pipeline is in use?

4,322 views
Skip to first unread message

Mark Stosberg

unread,
Feb 28, 2017, 2:24:42 PM2/28/17
to Jenkins Users
For cleaning up old builds, the "Discard Old Builds" plugin is recommended:


However, the instructions for reference a "post build" step which doesn't exist in the Configure interface for Multibranch Pipeline projects. 

What's the recommended way to clean-up builds from multi-branch pipeline projects? Ideally I'd like different pruning policies for different branches. 

Thanks,

     Mark

Baptiste Mathus

unread,
Mar 1, 2017, 4:08:53 AM3/1/17
to jenkins...@googlegroups.com
I don't think there's something per branch, but you probably want to either search JIRA and/or file a new feature request about it.

You shouldn't need a special plugin, this is a standard feature. Here's the way to do it with Declarative Pipeline: 

pipeline {
    options {
        buildDiscarder(logRotator(numToKeepStr: '20'))
    }
...
}


HTH

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1d9e0343-bbce-474f-a4fe-7623a4f39aaf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark Stosberg

unread,
Mar 1, 2017, 2:30:08 PM3/1/17
to Jenkins Users, m...@batmat.net
Thanks for reply, and for providing both the Pipeline syntax formats. This is the first time I noticed that there are two distinct Pipeline syntaxes.

I'm trying out the Scripted Pipeline syntax now.  

I tried to find documentation on the difference between 'numToKeepStr' and 'artifactNumToKeepStr' but couldn't. I set them both the same number in hopes that will have the desired effect of saving a particular number of builds. 

      Mark

On Wednesday, March 1, 2017 at 4:08:53 AM UTC-5, Baptiste Mathus wrote:
I don't think there's something per branch, but you probably want to either search JIRA and/or file a new feature request about it.

You shouldn't need a special plugin, this is a standard feature. Here's the way to do it with Declarative Pipeline: 

pipeline {
    options {
        buildDiscarder(logRotator(numToKeepStr: '20'))
    }
...
}


HTH
2017-02-28 20:24 GMT+01:00 Mark Stosberg <ma...@rideamigos.com>:
For cleaning up old builds, the "Discard Old Builds" plugin is recommended:


However, the instructions for reference a "post build" step which doesn't exist in the Configure interface for Multibranch Pipeline projects. 

What's the recommended way to clean-up builds from multi-branch pipeline projects? Ideally I'd like different pruning policies for different branches. 

Thanks,

     Mark

--
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.

Baptiste Mathus

unread,
Mar 1, 2017, 2:41:07 PM3/1/17
to jenkins...@googlegroups.com

Mark Stosberg

unread,
May 5, 2017, 4:06:04 PM5/5/17
to Jenkins Users, m...@batmat.net
On Wednesday, March 1, 2017 at 4:08:53 AM UTC-5, Baptiste Mathus wrote:
I don't think there's something per branch, but you probably want to either search JIRA and/or file a new feature request about it.

You shouldn't need a special plugin, this is a standard feature. Here's the way to do it with Declarative Pipeline: 

pipeline {
    options {
        buildDiscarder(logRotator(numToKeepStr: '20'))
    }
...
}



I'm stil not seeing any signs that the buildDiscarder plugin is working for me. At the top of my Jenkinsfile, I have this:

properties([[
 $class: 'jenkins.model.BuildDiscarderProperty',
  strategy: [$class: 'LogRotator', numToKeepStr: '50', artifactNumToKeepStr: '50']
]])

That's just above my  "node {}" block. 

From reading related source code at:

I can see that this function should generate some logging, but I can't find the log entries indicating this is running in either the web-based Jenkins log page, or under /var/log/jenkins/*

The effective-but-imperfect workaround I've found is to just manually delete only builds:

    find "/var/lib/jenkins/jobs/My Pipeline/branches/" -mindepth 3 -maxdepth 3 -type d -ctime +15 | xargs -d '\n' rm -rf

That doesn't have the safety nets of preserving any builds that are last-successful, promoted, etc. 

Some questions:

  * Should the logging I see in the source code *always* be happening or there something I need to do activate that logging?
  * Should properties() call work outside a node block?
  * Are there any serious drawbacks to just manually deleting old build myself? This built-in log rotation has proven especially time-consuming for what seems like it should be a simple feature to setup. 

Thanks,

      Mark

Kevin Brotcke

unread,
Nov 28, 2017, 6:50:48 PM11/28/17
to Jenkins Users
I also couldn't get the buildDiscarder working, nothing seems to be happening. In our case we create a lot of long lasting branches which filled up our Jenins server disk space pretty quickly. I wrote a quick Groovy script to delete old builds across all branches but I'd prefer a more integrated solution:

Mark Waite

unread,
Nov 28, 2017, 7:53:27 PM11/28/17
to Jenkins Users


On Tuesday, November 28, 2017 at 4:50:48 PM UTC-7, Kevin Brotcke wrote:
I also couldn't get the buildDiscarder working, nothing seems to be happening. In our case we create a lot of long lasting branches which filled up our Jenins server disk space pretty quickly. I wrote a quick Groovy script to delete old builds across all branches but I'd prefer a more integrated solution:



From scripted pipeline, I use properties([[$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '7']]]) and it works great.  I haven't tried it with declarative pipeline, but would be surprised if it did not work just as well there.

Mark Waite

Kevin Brotcke

unread,
Nov 29, 2017, 2:46:38 AM11/29/17
to jenkins...@googlegroups.com
I can confirm deleting old builds PER branch is working for declarative syntax by using the option:
options {
  buildDiscarder(logRotator(numToKeepStr:'10'))
}

But this doesn't really solve my problem. I want to keep max N builds across ALL branches in a multibranch pipeline to maintain a more predictable disk usage rate. That's what my Groovy script accomplishes.


--
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/_06kZ20xpEE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/265b88d6-3c72-4c0f-8c59-de35dabcafd5%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages