使用DSL的logrotator进行多分支管道作业配置

时间:2019-07-18 05:38:15

标签: jenkins jenkins-pipeline jenkins-groovy jenkins-job-dsl multibranch-pipeline

我正在使用jenkins job dsl配置我的多分支管道作业。实际上,除了logRotator之外,我的所有设置都可以使用。我的目的是删除旧版本并保留特定数量的版本。我可以使用

options {

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

为此目的在自由式工作中。多分支管道作业配置部分的UI中不包含丢弃旧的构建部分。有什么方法可以使用logRotator而不将其添加到我的jenkins文件中。

2 个答案:

答案 0 :(得分:0)

在Jenkins作业dsl中,multibranchPipelineJob可以添加以下行以丢弃旧版本。

orphanedItemStrategy {
            discardOldItems { numToKeep(10) }
        }

答案 1 :(得分:0)

我在代码中添加了以下部分,以在多分支管道作业中实现buildDiscarder功能。

 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")
              }
            }
          }
        }
      }
    }
  }
}
相关问题