0

I'm using jenkins job dsl to configure my multibranch pipeline jobs. Actually my all settings are working except logRotator. My aim is to delete the old builds and keep a particular number of build. I can use

options {

    buildDiscarder(logRotator(numToKeepStr: '10'))
  }

in freestyle job for this purpose. The multibranch pipeline job configure section not having discardold build section as an option in UI. Is there any way I can use the logRotator without adding this to my jenkins file.

SANITH
  • 3,147
  • 3
  • 13
  • 15

2 Answers2

1

I've added the following section in my code to implement the buildDiscarder functionality in multibranch pipeline jobs.

 multibranchPipelineJob("job") {
  branchSources {
  branchSource {
    source {
      bitbucket {
        credentialsId("myid")
        repoOwner("iam")
        repository("job")                       
 traits {
          headWildcardFilter {
            includes("branchestoinclude")
            excludes("toexclude")
          }
        }
      }
    }
    strategy {
      defaultBranchPropertyStrategy {
        props {
          buildRetentionBranchProperty {
            buildDiscarder {
              logRotator {
                daysToKeepStr("-1")
                numToKeepStr("8")
                artifactDaysToKeepStr("-1")
                artifactNumToKeepStr("-1")
              }
            }
          }
        }
      }
    }
  }
}
SANITH
  • 3,147
  • 3
  • 13
  • 15
-1

In Jenkins job dsl, the multibranchPipelineJob has an option to add the following lines for discarding old builds.

orphanedItemStrategy {
            discardOldItems { numToKeep(10) }
        }
eeedev
  • 149
  • 9
  • I'm having this section in my code. But orphanedItemStrategy won't give the build Discarder functionality. – SANITH Jul 22 '19 at 07:31