5

I'm having trouble getting my webhook in bitbucket server to start a Jenkins job. I've read through the other answered questions on here and can't get it going.

Bitbucket setup:

  • No special plugins installed
  • In repository settings I have a webhook set up
  • URL: http://[my jenkins url]/bitbucket-hook/ (yes I have the trailing slash)
  • Repo Push event selected

Jenkins setup:

  • Bitbucket plugin installed
  • Created new job
  • Set SCM to Git and added repo details
  • Set branches to build to either ** or refs/heads/rob-jenkins (a branch in git)
  • Build when a change is pushed to bitbucket selected

What I do: I make a change to a file in rob-jenkins branch, push and the job is not started in Jenkins.

What I see: In bitbucket, repo settings, webhooks I can see the webhook fired as soon as the commit is pushed. It has a 200 http status code, response body is empty.

In Jenkins I've set up a logger for

com.cloudbees.jenkins.plugins.BitbucketHookReceiver
com.cloudbees.jenkins.plugins.BitbucketJobProbe
com.cloudbees.jenkins.plugins.BitbucketPayloadProcessor
com.cloudbees.jenkins.plugins.BitBucketTrigger

And when I look at those logs I can see only 1 entry from com.cloudbees.jenkins.plugins.BitbucketHookReceiver

Received commit hook notification : {"eventKey":"repo:refs_changed","date":"2018-05-22T12:18:11+1000","actor":{"name":"xxxxxx","emailAddress":"xxxxxx@xxxxxx.com","id":53,"displayName":"xxxxxx","active":true,"slug":"xxxxxxx","type":"NORMAL"},"repository":{"slug":"xxxxx","id":1,"name":"xxxxx","scmId":"git","state":"AVAILABLE","statusMessage":"Available","forkable":true,"project":{"key":"SS","id":2,"name":"xxxxx","description":"xxxxxx","public":false,"type":"NORMAL"},"public":false},"changes":[{"ref":{"id":"refs/heads/rob-jenkins","displayId":"rob-jenkins","type":"BRANCH"},"refId":"refs/heads/rob-jenkins","fromHash":"1d9ad42fa404c893853094b0072e5b839f787589","toHash":"9bf7dc873f355259e4338ee80afbd246ecbb48a9","type":"UPDATE"}]}

There are no other entries in the log.

In the job itself, the BitBucket Hook Log screen just says "Polling has not run yet."

No idea why it isn't triggering the Jenkins job... what am I missing?

  • I've tried setting the Poll SCM manually and that didn't make a difference.
  • I've done a manual build and it works fine
Rob Ormond
  • 123
  • 1
  • 9

2 Answers2

3

as commented by @tomas-bjerre the resolution was to use a different plugin

I would recommend using thie plugin instead: github.com/jenkinsci/generic-webhook-trigger-plugin – Tomas Bjerre yesterday

Rob Ormond
  • 123
  • 1
  • 9
  • 2
    So there is no answer as to why the BitBucket webhook isn't triggering the Bitbucket plugin? I had it working fine...then now it has stopped for some unknown reason. I'd rather not switch the plugin. – Mike Oct 29 '18 at 16:59
3

No plugin needed. Just add a post-recieve hook under your repo in Bitbucket. On Jenkins, under Build Triggers, Trigger builds remotely (e.g., from scripts) Trigger builds remotely (e.g., from scripts) and specify an Authentication Token. A bash or python script can be used for the hook. Anytime a git push is run (not just a commit), you trigger a build!

venky
  • 31
  • 1
  • #!/usr/bin/python import sys from subprocess import call print " start post-receive hook on master or dev branch..." sys.stdout.flush() if __name__ == '__main__': for line in sys.stdin.xreadlines(): old, new, ref = line.strip().split(' ') if ref == 'refs/heads/master' or ref == 'refs/heads/dev': print " Pushing, trigger a Jenkins build. " print "===================================" sys.stdout.flush() call(["curl", "-ik", "http://jenkins.company.com:9080/job/${JOB_NAME}/build?token=xyz8a5bc77cdf631845a4e1c2e4d7153"]) – venky Jun 08 '18 at 19:18
  • Can you provide a link to some tutorial? I find this specific field in Jenkins documentation lacking (to say the least). – Daniel Jun 15 '18 at 18:48