【问题标题】:DSL Seed Job for Multibranch pipeline with Bitbucket branch plugin suppress auto build of branches带有 Bitbucket 分支插件的多分支管道的 DSL 种子作业抑制分支的自动构建
【发布时间】:2018-04-09 17:04:30
【问题描述】:

有一个 DSL 作业在 jenkins 中创建多分支管道作业,使用插件运行 Jenkins 2.107.1:'Branch API Plugin'2.0.18,'Bitbucket Branch Source Plugin'2.2.10。

我找不到合适的配置功能来启用“抑制自动 SCM 触发”属性,请帮助。

这是我的工作,但它只是在扫描分支时触发构建:

multibranchPipelineJob("job") {
  configure {
    it / sources / data / 'jenkins.branch.BranchSource' / source(class: 'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource') {
      credentialsId('..')
      id("..")
      checkoutCredentialsId("..")
      repoOwner("owner")
      repository("my-repo")
      includes()
      excludes("PR-*")
    }
  }
}

【问题讨论】:

    标签: jenkins dsl jenkins-job-dsl


    【解决方案1】:

    这就是它现在的工作方式......借助以下源代码:

    https://github.com/jenkinsci/bitbucket-branch-source-plugin

    multibranchPipelineJob("job") {
      branchSources {
        branchSource {
          source {
            bitbucket {
              credentialsId("myid")
              repoOwner("iam")
              repository("job")                       
              traits {
                headWildcardFilter {
                  includes("branchestoinclude")
                  excludes("toexclude")
                }
              }
            }
          }
          strategy {
            defaultBranchPropertyStrategy {
              props {
                // keep only the last 8 builds
                buildRetentionBranchProperty {
                  buildDiscarder {
                    logRotator {
                      daysToKeepStr("-1")
                      numToKeepStr("8")
                      artifactDaysToKeepStr("-1")
                      artifactNumToKeepStr("-1")
                    }
                  }
                }
              }
            }
          }
        }
      }
      // Branch behaviour
      configure {
        def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits
        traits << 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' {
          strategyId(3) // detect all branches -refer the plugin source code for various options
        }
      }
      orphanedItemStrategy {
        discardOldItems {
          numToKeep(8)
        }
      }
    }
    

    【讨论】:

    • 这里在哪里抑制 scm
    • 这在我的情况下是不需要的,因为当我提交更改时我会触发构建,我需要触发构建。如果您知道 SCM 触发的行为,您可以很好地使用它.. 但我不确定,但是您可以查看博客 stackoverflow.com/questions/47291748/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多