Check the logfile for any exceptions or similar.

To be sure that everything is working well, please check the following points:

  • Enabled Polling SCM (no schedule is necessary, so it can be empty)

  • Check the configured SCM URLs, they need to be identical.

  • Trigger manually the notification (Button called Trigger Jenkins) over the settings page in Bitbucket.

If it doesn't work now, try to trigger the poll manually with curl or similar tools:

curl -v http://<Jenkins URL>/git/notifyCommit?url=<SCM URL>

curl http://jenkins.com:8080/git/notifyCommit?url=ssh://git@bitbucket.com:7999/eee/repo.git

If it doesn't work, there is a problem with Jenkins.
If it works, check if all hook files are executable /data/repositories//hooks and /data/repositories//hooks/post-receive.d.

If it doesn't work now, try to get some debug information. To achieve it, you can simply activate the debug output. (see next section)

Enable debug output

You have two possibilities, activate general debug output or just for the needed classes:

General debug

curl \
  -u admin -v -X PUT -d "" \
  -H "Content-Type: application/json" \
  <Bitbucket URL>/rest/api/latest/logs/rootLogger/debug
CODE

Debug just the Notification class

curl \
  -u admin -v -X PUT -d "" \
  -H "Content-Type: application/json" \
  <Bitbucket URL>/rest/api/latest/logs/logger/com.nerdwin15.stash.webhook.Notifier/debug 
CODE

Debug just the test class for Jenkins settings

curl \
  -u admin -v -X PUT -d "" \
  -H "Content-Type: application/json" \
  <Bitbucket URL>/rest/api/latest/logs/logger/com.nerdwin15.stash.webhook.rest.JenkinsResource/debug 
CODE

Now you will get some more details about what is Bitbucket or the plugin doing.
To disable the debug output, restart your Bitbucket or run the following commands:

curl \
  -u admin -v -X PUT -d "" \
  -H "Content-Type: application/json" \
  <Bitbucket URL>/rest/api/latest/logs/rootLogger/warn 
CODE
curl \
  -u admin -v -X PUT -d "" \
  -H "Content-Type: application/json" \
  <Bitbucket URL>/rest/api/latest/logs/logger/com.nerdwin15.stash.webhook.Notifier/info 
CODE
curl \
  -u admin -v -X PUT -d "" \
  -H "Content-Type: application/json" \
  <Bitbucket URL>/rest/api/latest/logs/logger/com.nerdwin15.stash.webhook.rest.JenkinsResource/info 
CODE

Debugging at the Jenkins side

This plugin sends requests to Jenkins via the Jenkin Git Plugin URL http://<Jenkins URL>/git/notifyCommit?url=<SCM URL>. You can trace this request from TCP to Jenkins.

Examining TCP packets

To see the TCP packets sent to Jenkins, you can use tcpdump:

tcpdump -i any -A host <Jenkins IP> and tcp port <Jenkins Port Number>
CODE

The tcpdump command puts a lot of data on the screen, but you are looking for something like this:

GET /git/notifyCommit?url=SCM_URL&branches=BRANCH_NAME
CODE

Using the Jenkins logger

Jenkins has built-in logging capabilities. You can create a logger and see what Jenkins receives:

  1. Go to http://jenkins/log/new

  2. Set the name of the new log recorder: git

  3. Click Ok

  4. Add a Logger: hudson.plugins.git

  5. Save

Now trigger a build from Bitbucket using the "Trigger Build" button. Go to the logger page (http://jenkins/log/git) and reload it. You should see what the Jenkins Git Plugin received. It should look like this:

Received notification for uri = <SCM URL> ; sha1 = <SHA1> ; branches = <BRANCH_NAME>

Examining the Git Polling Log

You can also examine the Git Polling Log in the Job configuration page. The Git Plugin will only poll the repository if the URL and the branch match one of the jobs' configurations (all jobs using the Git Plugin are given the opportunity to poll if they match the request sent by Bitbucket).