Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-47717

Allow different "Discard Old Build" options per branch on multibranch pipelines

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Currently I'm setting a buildDiscarder option in my declarative Jenkinsfile.

      The problem is that I cannot setup a different strategy per branch.

      Why do it need this? Well, I'd like to keep during more time the build and artifacts of the master and release/* branches while I keep a low number for any other branch.

      I'm sure this will be useful for a lot of people.

        Attachments

          Activity

          Hide
          mulmschneider Martin Ulmschneider added a comment - - edited

          I'm running into the same problem, and am surprised that this doesn't seem to be a common issue - how do other people handle loads of feature branch / pull request builds?

          Edit:

          I'm using the following code snippet as a workaround:

                  script{
                    if (env.BRANCH_NAME=='master'){
                      echo 'master branch - disable build discarding'
                      properties([buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: ''))])
                    }
                    else {
                      echo 'non-master branch - only keeping the last 5 build artifacts'
                      properties([buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '5', daysToKeepStr: '', numToKeepStr: ''))])
                    }
          
          
          Show
          mulmschneider Martin Ulmschneider added a comment - - edited I'm running into the same problem, and am surprised that this doesn't seem to be a common issue - how do other people handle loads of feature branch / pull request builds? Edit: I'm using the following code snippet as a workaround: script{ if (env.BRANCH_NAME== 'master' ){ echo 'master branch - disable build discarding' properties([buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: ' ', daysToKeepStr: ' ', numToKeepStr: ' '))]) } else { echo 'non-master branch - only keeping the last 5 build artifacts' properties([buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: ' 5 ', daysToKeepStr: ' ', numToKeepStr: ' '))]) }
          Hide
          richajam James Richardson added a comment -

          buildDiscarder(logRotator(numToKeepStr: env.BRANCH_NAME == 'master' ? '10' : '25'))

           

          Show
          richajam James Richardson added a comment - buildDiscarder(logRotator(numToKeepStr: env.BRANCH_NAME == 'master' ? '10' : '25'))  

            People

            • Assignee:
              abayer Andrew Bayer
              Reporter:
              c3s4r Cesar Salazar
            • Votes:
              8 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

              • Created:
                Updated: