How to Trigger Non-Multibranch Jobs from Bitbucket Cloud?

Article ID:115000051092
2 minute readKnowledge base

Issue

  • I want to configure Jenkins and Bitbucket Cloud to automatically trigger non-multibranch jobs on changes

Resolution

The Bitbucket Plugin provides support in Jenkins to process webhooks received from Bitbucket Cloud.

Configuration in Jenkins

Freestyle Jobs

Configure the Git SCM:

bitbucket cloud freestyle git config

Configure the project to Build when a change is pushed to Bitbucket:

job bbplugin trigger

Pipeline Jobs

1) Configure the Pipeline script from SCM:

bitbucket cloud pipeline git config

Or a Pipeline script:

node {
	checkout([$class: 'GitSCM',
	    branches: [[name: '*/develop']],
	    doGenerateSubmoduleConfigurations: false,
	    extensions: [],
	    submoduleCfg: [],
	    userRemoteConfigs: [[
	        credentialsId: 'dohbedoh-bitbucket-up',
	        url: 'https://bitbucket.org/jenkinssupport/simple-project.git'
    ]]])
}

Configure the project to Build when a change is pushed to Bitbucket:

job bbplugin trigger

IMPORTANT: Build the project once to retrieve the Git data.

Configuration in Bitbucket Server side

Go to the Settings of a repository. Then go to the section Webhooks and click on Add Webhook:

bitbucket cloud webhooks

Give it the name you want and specify the Bitbucket Branch Source endpoint $JENKINS_URL/bitbucket-hook/:

bitbucket cloud bbplugin webhook add

Ensure that the webhook is created and enabled:

bitbucket cloud bbplugin webhook added

From now on, Push events to the repository notifies the Git plugin and triggers a new build.

Pull Requests

(We strongly encourage to use Pipeline Multibranch for such scenario)

There is currently no simple solution to trigger jobs on Pull Requests for Bitbucket Cloud. There is some work in progress in the Bitbucket Plugin to make this possible. This is tracked by JENKINS-23685.

In the meantime, the workaround is to use polling solution like Bitbucket Pullrequest Builder

Troubleshooting

Please have a look at Bitbucket Webhooks Troubleshooting to troubleshoot issues with these solutions.