Search code examples
jenkinsjenkins-pluginsjenkins-job-dsl

Jenkins job dsl for bitbucket branch source plugin documentation with complete examples?


I currently have this:

multibranchPipelineJob("myjob") {
  branchSources {
    branchSource {
      source {
        bitbucket {
          credentialsId('bitbucket-login-user-pass')
          repoOwner('myteam')
          repository('myrepo')
          autoRegisterHook(true)
        }
      }
    }
  }
}

But I also need to add the following settings: enter image description here

How do I add these settings in the config? Are they "traits" where do I go to see what traits I have available?


Solution

  • this is what I use (bitbucket wrapped with organizationFolder):

    organizationFolder('example') {
        description('This contains branch source jobs for Bitbucket')
        displayName('The Organization Folder')
        triggers {
            periodic(86400)
        }
        organizations {
            bitbucket {
              repoOwner('myorg')
              credentialsId('BITBUCKET_CRED')
              autoRegisterHooks(false)
              traits {
                sourceRegexFilter {
                  // A Java regular expression to restrict the project names.
                  regex('.*')
                }
              }
            }
        }
        properties {
            mavenConfigFolderOverrideProperty {
                override(true)
                settings {
                    settingsConfigId('DEFAULT_MAVEN_SETTINGS')
                }
            }
        }
        // discover Branches (workaround due to JENKINS-46202)
        configure { node ->
            // node represents <jenkins.branch.OrganizationFolder>        
            def traits = node / 'navigators' / 'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMNavigator' / 'traits'
            traits << 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' {
                strategyId(3) // detect all branches
            }
        }    
    }