1

how to i set discard old build in this script code in jenkins pipelinejob? i am using this config in jenkins helm value on kubernetes

          - script: >
              pipelineJob('my-job') {
                  properties {
                         disableConcurrentBuilds()
                         pipelineTriggers {
                            triggers {
                                gitlab {
                                    triggerOnPush(true)
                                    branchFilterType('NameBasedFilter')
                                    includeBranchesSpec('staging') 
                                    secretToken('123456')
                                    cancelPendingBuildsOnUpdate(true)
                                }
                            }
                         }
                  }
                  definition {
                      cpsScm {
                          scriptPath 'jenkinsfile'
                          scm {
                            git {
                                remote {
                                  credentials 'user'
                                  url 'git-repo'
                                }
                                branch 'staging'
                                extensions {}
                            }
                          }
                      }
                  }
              }
  • Is this answer helpful? - https://stackoverflow.com/a/44155346/17490003 – Pamela Sarkisyan Dec 12 '21 at 19:13
  • @jalal here is the [documentation](https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.jobs.FreeStyleJob.logRotator) for the log rotator in the Job DSL plugin. Under your `pipelineJob` directive just use something like: `logRotator(30, -1, 1, -1)` – Noam Helmer Dec 13 '21 at 15:14

1 Answers1

1

I find it.

          - script: >
              pipelineJob('my-job') {
                  logRotator {
                      numToKeep(10)
                      artifactNumToKeep(10)
                  }
                  properties {
                         disableConcurrentBuilds()
                         pipelineTriggers {
                            triggers {
                                gitlab {
                                    triggerOnPush(true)
                                    branchFilterType('NameBasedFilter')
                                    includeBranchesSpec('staging') 
                                    secretToken('123456')
                                    cancelPendingBuildsOnUpdate(true)
                                }
                            }
                         }
                  }
                  definition {
                      cpsScm {
                          scriptPath 'jenkinsfile'
                          scm {
                            git {
                                remote {
                                  credentials 'user'
                                  url 'git-repo'
                                }
                                branch 'staging'
                                extensions {}
                            }
                          }
                      }
                  }
              }