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

1,799 views
Skip to first unread message

red 888

unread,
Jul 2, 2018, 1:35:37 PM7/2/18
to job-dsl-plugin

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?


I tried using originPullRequestDiscoveryTrait but I get: ERROR: Found multiple extensions which provide method originPullRequestDiscoveryTrait with arguments [script$_run_closure1$_closure3$_closure4$_closure5$_closure6$_closure7$_closure8@3ae03409]: [[com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait, org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait]]


This doesn't seem to work:

            traits {

              // discover PRs

              //BranchDiscoveryTrait {

              //  strategyId(1) // Exclude branches that are also filed as PRs

              //  //strategyId(2) // Only branches that are also filed as PRs

              //  //strategyId(3) // All branches

              //}

              //ForkPullRequestDiscoveryTrait {

              //  strategyId(1) // 

              //  //strategyId(2) // 

              //  //strategyId(3) // 

              //}

              originPullRequestDiscoveryTrait {

                strategyId(1) // Merging the pull request with the current target branch revision

                //strategyId(2) // The current pull request revision

                //strategyId(3) // Both the current pull request revision and the pull request merged with the current target branch revision

              }

            }


Toni Van de Voorde

unread,
Jul 2, 2018, 2:50:15 PM7/2/18
to job-dsl...@googlegroups.com
Hi,

Following is my working config:

multibranchPipelineJob('adsdaq/print/engine') {
  branchSources {
    branchSource {
      source {
        bitbucket {
          id('bitbucket')
          serverUrl('https://bitbucket.org')
          repoOwner('xxx')
          repository('xxx')
          credentialsId('xxx')
        }
      }
    }
  }

  triggers {
    periodic(30)
  }

  // discover Branches (workaround due to JENKINS-46202)
  configure {
    def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits
    traits << 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' {
      strategyId(1)
    }
    traits << 'com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait' {
      strategyId(1)
    }
  }

  orphanedItemStrategy {
      discardOldItems {
          numToKeep(0)
      }
  }
}

Cheers

--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugi...@googlegroups.com.
To post to this group, send email to job-dsl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/6cff6a7e-241c-479e-ac78-218799e27102%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

red 888

unread,
Jul 2, 2018, 3:32:38 PM7/2/18
to job-dsl-plugin
yeah DSL support is broken so direct xml editing seems to be the only way, but how do you set webhooks config? 

In the xml under traits it looks like this:
            <com.cloudbees.jenkins.plugins.bitbucket.WebhookRegistrationTrait>
             
<mode>ITEM</mode>
            </com.cloudbees.jenkins.plugins.bitbucket.WebhookRegistrationTrait

Catalin P

unread,
Jul 4, 2018, 3:53:55 AM7/4/18
to job-dsl-plugin
Usually I configure the webhook in "Manage Jenkins" > "Configure System" > "Bitbucket Endpoints" and I don't have to specify that on each job. If you have configured your endpoint correctly and checked "Manage hooks" you don't need to override that in the job.
But if you still want to enable on per job basis maybe something like below will work:

configure {
    def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits
    traits << 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' {
     strategyId(1) // detect all branches -refer the plugin source code for various options
    }
    traits << 'com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait' {
     strategyId(1)
    }
    traits << 'com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait' {
     strategyId(1)
    }
    traits << 'com.cloudbees.jenkins.plugins.bitbucket.WebhookRegistrationTrait' {
      mode(ITEM)
    }
  }

Toni Van de Voorde

unread,
Jul 4, 2018, 4:51:09 AM7/4/18
to job-dsl-plugin
Hi Catelin,

In the Bitbucket Endpoints I don't see a way to configure the branch discovery defaults ?! I only see that you can specify the credentials ...

Catalin P

unread,
Jul 4, 2018, 7:45:13 AM7/4/18
to job-dsl-plugin
I believe you can set that in the jenkins job, Branch Sources > Bitbucket > "Behaviours" > "Filter by name (with wildcards)" or "Filter by name (with regular expression)". As for the dsl you should be able to get that from the config.xml and inject it via traits as on the above example.

Toni Van de Voorde

unread,
Jul 4, 2018, 7:49:04 AM7/4/18
to job-dsl-plugin
Ah yes. Sorry I though you said that it was possible to defined the default strategy in the global configuration somewhere. Obviously what red888 (and myself) need to do is to define this via DSL.

Thanks though

red 888

unread,
Jul 6, 2018, 10:51:14 AM7/6/18
to job-dsl-plugin
Thanks for the help that totally works
Reply all
Reply to author
Forward
0 new messages