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

Different behavior of the plugin to receive webhook

XMLWordPrintable

      A large organization is not able to receive trigger build from bitbucket server. All the webhook was configured without server_url. They stop to work from commit:

      git show 44f0152d5edf5ff3942d4fdc3cbd065e765c55c6

      JENKINS-74983 Add support for authenticated Webhooks registered in Bitbucket (#1044)

      Verify in the webhooks processor when the signature is present is matches the configured
      Add configuration in the global settings to setup HMAC credentials. The secret is not customisable by single project for the following reasons:

      • events should contains a duplicate of the payload to be verified only in BitbucketSCMSource.retrieve method.
      • that means spend a lot of resources just to ignore the payload. Multiple fake requests, would overload Jenkins that have to process events to lookup the right project.
      • could not response to Bitbucket that the payload is invalid because events are managed async.
      • each event could serve multiple projects that potentially could be configured with a different secret.

      The commit is not the problem but this small change yes:

      -        if (instanceType == null && serverUrl != null) {
      +        if (instanceType == null && serverURL != null) {
                   LOGGER.log(Level.FINE, "server_url request parameter found. Bitbucket Native Server webhook incoming.");
                   instanceType = BitbucketType.SERVER;
               } else {
                   LOGGER.log(Level.FINE, "X-Bitbucket-Type header / server_url request parameter not found. Bitbucket Cloud webhook incoming.");
      +            instanceType = BitbucketType.CLOUD;
      +            serverURL = BitbucketCloudEndpoint.SERVER_URL;
      +        }
      +
      

      Basically the hook was coming even was printing X-Bitbucket-Type header / server_url request parameter not found. Bitbucket Cloud webhook incoming.

      In order to fix I have this proposed change:

      diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/BitbucketSCMSourcePushHookReceiver.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/BitbucketSCMSourcePushHookReceiver.java
      index 68b012f..5d70904 100644
      --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/BitbucketSCMSourcePushHookReceiver.java
      +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/BitbucketSCMSourcePushHookReceiver.java
      @@ -109,13 +109,14 @@ public class BitbucketSCMSourcePushHookReceiver extends CrumbExclusion implement
       
               String bitbucketKey = req.getHeader("X-Bitbucket-Type"); // specific header from Plugin implementation
               String serverURL = req.getParameter("server_url");
      +        String requestUUID = req.getParameter("X-Request-UUID"); // specific from cloud server
       
               BitbucketType instanceType = null;
               if (bitbucketKey != null) {
                   instanceType = BitbucketType.fromString(bitbucketKey);
                   LOGGER.log(Level.FINE, "X-Bitbucket-Type header found {0}.", instanceType);
               }
      -        if (serverURL != null) {
      +        if (serverURL != null || requestUUID == null) {
                   if (instanceType == null) {
                       LOGGER.log(Level.FINE, "server_url request parameter found. Bitbucket Native Server webhook incoming.");
                       instanceType = BitbucketType.SERVER;
      

      This should allow to fallback to the old behavior

            nfalco Nikolas Falco
            panicking Michael Nazzareno
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: