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 Enable the debug output.
Enable the debug output
There are two possibilities: activate general debug output or just the necessary classes:
General debug
curl \ -u admin -v -X PUT -d "" \ -H "Content-Type: application/json" \ <Bitbucket URL>/rest/api/latest/logs/rootLogger/debug
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
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
This allows you to gather additional information regarding Bitbucket
or the plugin.
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
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
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
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>
. Trace this request from TCP to Jenkins.
Examining TCP packets
To see the TCP packets sent to Jenkins, use tcpdump
:
tcpdump -i any -A host <Jenkins IP> and tcp port <Jenkins Port Number>
The tcpdump
command displays a lot of data, but you are looking for something like this:
GET /git/notifyCommit?url=SCM_URL&branches=BRANCH_NAME
Using the Jenkins logger
Jenkins has built-in logging capabilities. You can create a logger and see what Jenkins receives:
Go to http://jenkins/log/new
Set the name of the new log recorder:
git
Click OK.
Add a Logger:
hudson.plugins.git
Click Save.
Now click Trigger Build to trigger a build from Bitbucket
. Go to the logger page (http://jenkins/log/git) and reload the page. You should now 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 only polls 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
).