Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-28877

Bitbucket Plugin unable to parse Bitbucket webhook response json

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Blocker Blocker
    • bitbucket-plugin
    • Jenkins 1.617, bitbucket-plugin 1.1.0
      Jenkins 2.25, bitbucket-plugin 1.1.5

      Trying to use the bitbucket hook and so far as I can tell, I guess that it is sending a JSON body without specifying a user. I wasn't able to retrieve the JSON that it was sending, but it seems like that field is not a guaranteed field.

      Error while serving http://104.236.89.214/bitbucket-hook/
      java.lang.reflect.InvocationTargetException
      ...
      Caused by: net.sf.json.JSONException: JSONObject["user"] not found.
      at net.sf.json.JSONObject.getString(JSONObject.java:2040)
      at com.cloudbees.jenkins.plugins.BitbucketHookReceiver.processPayload(BitbucketHookReceiver.java:104)
      at com.cloudbees.jenkins.plugins.BitbucketHookReceiver.doIndex(BitbucketHookReceiver.java:59)

      The offending line:
      String user = payload.getString("user");

          [JENKINS-28877] Bitbucket Plugin unable to parse Bitbucket webhook response json

          Charles DuBose created issue -

          Seems like bitbucket scheme is to now use 'actor'

          Robin Southgate added a comment - Seems like bitbucket scheme is to now use 'actor'

          Tony Lopez added a comment -

          Agreed. Bitbucket changed their payload response, per this document.

          Tony Lopez added a comment - Agreed. Bitbucket changed their payload response, per this document .
          Tony Lopez made changes -
          Summary Original: bitbucket can send webhook without user specified New: Bitbucket Plugin unable to parse Bitbucket webhook response json

          I was playing a little bit around the problem and the bitbucket-plugin sources...

          Since also the "repository" section of the payload has changed, it will fail also at row 105

                  String url = payload.getString("canon_url") + repo.getString("absolute_url");
          

          Carlo Alberto Degli Atti added a comment - I was playing a little bit around the problem and the bitbucket-plugin sources... Since also the "repository" section of the payload has changed, it will fail also at row 105 String url = payload.getString( "canon_url" ) + repo.getString( "absolute_url" );

          Kevin Zusy added a comment - - edited

          Hey all. I ran into the same issue and was able to get it working by making some modifications. Ended up using actor.username instead of user, repository.links.html.href instead of canon_url + absolute_url, and then removed the check for scm since that's no longer included. See https://github.com/jenkinsci/bitbucket-plugin/pull/15 for more details

          Kevin Zusy added a comment - - edited Hey all. I ran into the same issue and was able to get it working by making some modifications. Ended up using actor.username instead of user, repository.links.html.href instead of canon_url + absolute_url, and then removed the check for scm since that's no longer included. See https://github.com/jenkinsci/bitbucket-plugin/pull/15 for more details

          Dave Thomas added a comment -

          I am also getting an error 500 from within bitbucket. When I go to the JENKINS_URL/bitbucket-hook/ it gives me the following error:

          javax.servlet.ServletException: net.sf.json.JSONException: A JSONObject text must begin with '{' at character 0 of 
          	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:796)
          	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
          	at org.kohsuke.stapler.MetaClass$13.dispatch(MetaClass.java:411)
          	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)
          	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
          	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:649)
          	at org.kohsuke.stapler.Stapler.service(Stapler.java:238)
          

          Dave Thomas added a comment - I am also getting an error 500 from within bitbucket. When I go to the JENKINS_URL/bitbucket-hook/ it gives me the following error: javax.servlet.ServletException: net.sf.json.JSONException: A JSONObject text must begin with '{' at character 0 of at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:796) at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876) at org.kohsuke.stapler.MetaClass$13.dispatch(MetaClass.java:411) at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746) at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876) at org.kohsuke.stapler.Stapler.invoke(Stapler.java:649) at org.kohsuke.stapler.Stapler.service(Stapler.java:238)

          Hey Dave,
          is your Jenkins under https?

          Carlo Alberto Degli Atti added a comment - Hey Dave, is your Jenkins under https?

          Dave Thomas added a comment -

          Hi Carlo,

          The Jenkins instance isn't under https at this time, would that be the issue?

          Thanks

          Dave Thomas added a comment - Hi Carlo, The Jenkins instance isn't under https at this time, would that be the issue? Thanks

          anix no, you don't have to be under https... (but if you are, you absolutely need to have a valid certificate signed by a public authority... otherwise you won't receive any payload... )..

          Carlo Alberto Degli Atti added a comment - anix no, you don't have to be under https... (but if you are, you absolutely need to have a valid certificate signed by a public authority... otherwise you won't receive any payload... )..

            fbelzunc Félix Belzunce Arcos
            kayakyakr Charles DuBose
            Votes:
            24 Vote for this issue
            Watchers:
            44 Start watching this issue

              Created:
              Updated:
              Resolved: