How do I get Jenkins to build on push to a BitBucket git repository?

Solution 1:

Due to the Jenkins Hook of Bitbucket is not working at all for me and I have different Jenkins projects for different branches I had come to this solution:

  • Install Bitbucket Plugin at your Jenkins
  • Add a normal Post as Hook to your Bitbucket repository (Settings -> Hooks) and use following url:

https://YOUR.JENKINS.SERVER:PORT/bitbucket-hook/

and if you have setup authentication on jenkins then URL must be like

https://USERNAME:[email protected]:PORT/bitbucket-hook/

  • Configure your Jenkins project as follows:
  • under build trigger enable Build when a change is pushed to BitBucket
  • under Source Code Management select GIT; enter your credentials and define Branches to build (like **feature/*)

By this way I have three build projects, one for all features, one for develop and one for release branch. Make sure to include the slash ('/') on the end of the URL or the hook won't work.

And best of it, you don't have to ad new hooks for new Jenkins projects.

Solution 2:

I have our Jenkins instance set up to poll the repository every minute. Is that not frequent enough for your needs?

Our Jenkins configuration:

Build Triggers > Poll SCM = Checked

Build Triggers > Poll SCM > Schedule =

# every 1 minute
*/1 * * * *

Solution 3:

You can actually get this to work in Jenkins with the Bitbucket service, but it took some playing around to get it working.

If you use authentication, you can grab an API token from one of the users that can create builds. I created a separate account just for Bitbucket. You'll need at least Jenkins 1.426 to use the API token. You can then use HTTP authentication with the API token as your password for the Bitbucket service.

This is how mine is set up:

Endpoint: http://[bitbucket]:[APITOKEN]@[www.example.com/jenkins/]

Project Name: [NameOfMyJenkinsProject]

Module Name: [empty]

Token: [Token found in Jenkins project settings]

After I set it up like this, I was able to use the token as well as authentication to enable push-triggered builds from Bitbucket.

Solution 4:

The token stuff is useless if you use authentication in Jenkins.

use the Git plugin, and use a POST hook with http[s]://your.site.com[/jenkins]/git/[email protected]:your-username/your-repo.git in it. Be sure that polling is on and schedule at some value, or this won't work.