What does bitbucket webhook do?
When code is pushed to bitbucket, it’s suppose to trigger our Jenkins webhook URL in order to automate the continuous integration process where Jenkins will build and deploy the project.
Then one day it stop working
Bitbucket failed to trigger the automated build at our Jenkins instance. A workaround for this is to setup the Poll SCM to scan for configurable interval time, but that’s not the scope right now.
You can see the history of bitbucket pushes to Jenkins webhook URL (you have to enable the ‘history’ if you want to see the push events history) in bitbucket web. There is some error of response code 500 from Jenkins.
JSONObject[“username”] not found
It was pretty much clueless from the Jenkins response. Digging at Jenkins (docker container) logs reveals the error of JSONObject[“username”] not found, which is not really helpful.
2020-02-26 13:35:01.105+0000 [id=616616] WARNING o.e.j.s.h.ContextHandler$Context#log: Error while serving http://build.speedrent.com/bitbucket-hook/ net.sf.json.JSONException: JSONObject["username"] not found. at net.sf.json.JSONObject.getString(JSONObject.java:2040) at com.cloudbees.jenkins.plugins.BitbucketPayloadProcessor.processWebhookPayload(BitbucketPayloadProcessor.java:46) at com.cloudbees.jenkins.plugins.BitbucketPayloadProcessor.processPayload(BitbucketPayloadProcessor.java:28) at com.cloudbees.jenkins.plugins.BitbucketHookReceiver.doIndex(BitbucketHookReceiver.java:54) at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627) at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:396)
A quick googling on this brings me to this Jenkins issue. Apparently bitbucket has recently deprecated the username attribute and removed the push API. The solution is simple, update the bitbucket plugin 1.1.8 to 1.1.11 and viola it works!