How to Trigger Non-Multibranch Jobs from BitBucket Cloud

Issue

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

Environment

Resolution

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

Configuration in Jenkins

Freestyle Jobs

Configure the Git SCM:

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

Pipeline Jobs

1) Configure the Pipeline script from SCM:

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:

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:

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

Ensure that the webhook is created and enabled:

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.

Moreover as there is no refspec for repository pull requests in BitBucket Cloud, it makes it difficult to leverage for example the push notification endpoint of the Git Plugin.

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.

References

Bitbucket Integration

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.