6

Have a DSL job to create multibranch pipeline jobs in jenkins, running Jenkins 2.107.1 with plugins: 'Branch API Plugin' 2.0.18, 'Bitbucket Branch Source Plugin' 2.2.10.

I'm unable to find a proper configuration function to enable property to "Suppress automatic SCM triggering", please help.

Here is my job that works but its just triggers the build as soon as it scans for branch:

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-*")
    }
  }
}
Paweł Prażak
  • 3,091
  • 1
  • 27
  • 42

1 Answers1

7

This is how it works now... with the help of the following source code:

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)
    }
  }
}
Paweł Prażak
  • 3,091
  • 1
  • 27
  • 42
  • where is suppress scm here – red888 Oct 23 '18 at 01:24
  • that was not need on my case because, i would beed to trigger build when i commit changes, i would need to trigger build. If you know the behaviour of SCM triggering you can very well use it.. but I am not sure, however you can check the blog https://stackoverflow.com/questions/47291748/adding-suppress-automatic-scm-triggering-except-for-named-branches-in-jenkins-jo – Prakash Dharmalingam Oct 29 '18 at 15:45
  • I coped the answer into https://job-dsl.herokuapp.com/ and got this error: javaposse.jobdsl.dsl.DslScriptException: (script, line 3) No signature of method: javaposse.jobdsl.dsl.helpers.workflow.BranchSourcesContext.branchSource() – Nobe's Mar 24 '22 at 08:07
  • I ran the DSL job in Jenkins and it worked - not sure why job-dsl.herokuapp threw an error – Nobe's Mar 25 '22 at 11:20