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

Could not send notifications to Bitbucket Server when pull request is from fork

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • None
    • Jenkins 2.479.2
      Bitbucket Branch Source plugin 933.v7119e94e8f56
      Bitbucket Server 7
    • 935.1.1

      The Bitbucket Branch Source plugin version 930.ve6a_885b_3558f or later is unable to send build status notifications to Bitbucket Server, when Jenkins is building a pull request from a fork, and read access to the source repository of the PR has not been granted in Bitbucket. (If read access to the target repository of the PR had not been granted, then Jenkins would not even know about the PR.) This error did not occur in Bitbucket Branch Source 922.va_71d0e0b_7b_8d.

      The Jenkins console log shows:

      [Bitbucket] Notifying pull request build result
      ERROR: Could not send notifications
      com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRequestException: HTTP request error. Status: 401: .
      HttpResponseProxy{HTTP/1.1 401  [X-AREQUESTID: @1NS3KNXx914x317527x0, X-AUSERID: [REDACTED], X-AUSERNAME: [REDACTED], Cache-Control: no-cache, no-transform, Vary: x-ausername,x-auserid,cookie,accept-encoding, X-Content-Type-Options: nosniff, WWW-Authenticate: OAuth realm="https%3A%2F%2Fbitbucket.[REDACTED]", Content-Type: application/json;charset=UTF-8, Transfer-Encoding: chunked, Date: Mon, 09 Dec 2024 13:14:04 GMT, Keep-Alive: timeout=20, Connection: keep-alive] org.apache.http.client.entity.DecompressingEntity@28ea3beb}
      	at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.doRequest(BitbucketServerAPIClient.java:1097)
      	at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.postRequest(BitbucketServerAPIClient.java:1078)
      	at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.postRequest(BitbucketServerAPIClient.java:1074)
      	at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.postBuildStatus(BitbucketServerAPIClient.java:521)
      	at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketChangesetCommentNotifier.buildStatus(BitbucketChangesetCommentNotifier.java:50)
      	at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications.createStatus(BitbucketBuildStatusNotifications.java:173)
      	at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications.sendNotifications(BitbucketBuildStatusNotifications.java:237)
      	at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications$JobCheckoutListener.onCheckout(BitbucketBuildStatusNotifications.java:296)
      	at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:182)
      	at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:101)
      	at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:88)
      	at PluginClassLoader for workflow-step-api//org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
      	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
      	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
      	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
      	at java.base/java.lang.Thread.run(Thread.java:840)
      

      Desired changes:

      • Document the need to grant this access.
      • Make the plugin show which repository it attempted to access, when it gets this HTTP 401 error.

          [JENKINS-74970] Could not send notifications to Bitbucket Server when pull request is from fork

          Kalle Niemitalo created issue -

          Kalle Niemitalo added a comment - - edited

          I assigned this to myself because I intend to find which change caused this regression and how it should be fixed.

          Bitbucket Branch Source Branch PR from same repo PR from fork
          922.va_71d0e0b_7b_8d OK OK OK
          930.ve6a_885b_3558f OK OK FAIL, HTTP status 401
          932.vff504b_2003fe OK OK FAIL, HTTP status 401
          933.v7119e94e8f56 OK OK FAIL, HTTP status 401

          Kalle Niemitalo added a comment - - edited I assigned this to myself because I intend to find which change caused this regression and how it should be fixed. Bitbucket Branch Source Branch PR from same repo PR from fork 922.va_71d0e0b_7b_8d OK OK OK 930.ve6a_885b_3558f OK OK FAIL, HTTP status 401 932.vff504b_2003fe OK OK FAIL, HTTP status 401 933.v7119e94e8f56 OK OK FAIL, HTTP status 401
          Kalle Niemitalo made changes -
          Description Original: The Bitbucket Branch Source plugin is unable to send build status notifications to Bitbucket Server 7. The Jenkins console log shows:

          {noformat}
          [Bitbucket] Notifying pull request build result
          ERROR: Could not send notifications
          com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRequestException: HTTP request error. Status: 401: .
          HttpResponseProxy{HTTP/1.1 401 [X-AREQUESTID: @1NS3KNXx914x317527x0, X-AUSERID: [REDACTED], X-AUSERNAME: [REDACTED], Cache-Control: no-cache, no-transform, Vary: x-ausername,x-auserid,cookie,accept-encoding, X-Content-Type-Options: nosniff, WWW-Authenticate: OAuth realm="https%3A%2F%2Fbitbucket.[REDACTED]", Content-Type: application/json;charset=UTF-8, Transfer-Encoding: chunked, Date: Mon, 09 Dec 2024 13:14:04 GMT, Keep-Alive: timeout=20, Connection: keep-alive] org.apache.http.client.entity.DecompressingEntity@28ea3beb}
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.doRequest(BitbucketServerAPIClient.java:1097)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.postRequest(BitbucketServerAPIClient.java:1078)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.postRequest(BitbucketServerAPIClient.java:1074)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.postBuildStatus(BitbucketServerAPIClient.java:521)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketChangesetCommentNotifier.buildStatus(BitbucketChangesetCommentNotifier.java:50)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications.createStatus(BitbucketBuildStatusNotifications.java:173)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications.sendNotifications(BitbucketBuildStatusNotifications.java:237)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications$JobCheckoutListener.onCheckout(BitbucketBuildStatusNotifications.java:296)
          at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:182)
          at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:101)
          at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:88)
          at PluginClassLoader for workflow-step-api//org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
          at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
          at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
          at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
          at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
          at java.base/java.lang.Thread.run(Thread.java:840)
          {noformat}
          New: The Bitbucket Branch Source 933.v7119e94e8f56 plugin is unable to send build status notifications to Bitbucket Server 7. The Jenkins console log shows:

          {noformat}
          [Bitbucket] Notifying pull request build result
          ERROR: Could not send notifications
          com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRequestException: HTTP request error. Status: 401: .
          HttpResponseProxy{HTTP/1.1 401 [X-AREQUESTID: @1NS3KNXx914x317527x0, X-AUSERID: [REDACTED], X-AUSERNAME: [REDACTED], Cache-Control: no-cache, no-transform, Vary: x-ausername,x-auserid,cookie,accept-encoding, X-Content-Type-Options: nosniff, WWW-Authenticate: OAuth realm="https%3A%2F%2Fbitbucket.[REDACTED]", Content-Type: application/json;charset=UTF-8, Transfer-Encoding: chunked, Date: Mon, 09 Dec 2024 13:14:04 GMT, Keep-Alive: timeout=20, Connection: keep-alive] org.apache.http.client.entity.DecompressingEntity@28ea3beb}
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.doRequest(BitbucketServerAPIClient.java:1097)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.postRequest(BitbucketServerAPIClient.java:1078)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.postRequest(BitbucketServerAPIClient.java:1074)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.postBuildStatus(BitbucketServerAPIClient.java:521)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketChangesetCommentNotifier.buildStatus(BitbucketChangesetCommentNotifier.java:50)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications.createStatus(BitbucketBuildStatusNotifications.java:173)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications.sendNotifications(BitbucketBuildStatusNotifications.java:237)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications$JobCheckoutListener.onCheckout(BitbucketBuildStatusNotifications.java:296)
          at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:182)
          at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:101)
          at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:88)
          at PluginClassLoader for workflow-step-api//org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
          at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
          at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
          at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
          at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
          at java.base/java.lang.Thread.run(Thread.java:840)
          {noformat}
          Kalle Niemitalo made changes -
          Link New: This issue is caused by JENKINS-74965 [ JENKINS-74965 ]

          Nikolas Falco added a comment - - edited

          Which kind of authentication are you using?

          Nikolas Falco added a comment - - edited Which kind of authentication are you using?

          Nikolas Falco added a comment -

          In the PR you refer the authenticator was not changed in configureRequest method. In the OAuth2 the token is retrieved lazy but the code is the same.
          Maybe be in some previous commit 7ac886d4 ?

          Nikolas Falco added a comment - In the PR you refer the authenticator was not changed in configureRequest method. In the OAuth2 the token is retrieved lazy but the code is the same. Maybe be in some previous commit 7ac886d4 ?
          Nikolas Falco made changes -
          Priority Original: Minor [ 4 ] New: Major [ 3 ]

          BitbucketSCMSource.credentialsId refers to an instance of com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl in the system credential store. It has GLOBAL scope and no domain restrictions.

          The store also contains two credentials of other types but those should not matter here.

          nfalco, I believe I'll be able to diagnose and fix this issue, but it will take some time because I must not disrupt other users of the Jenkins instance.

          Kalle Niemitalo added a comment - BitbucketSCMSource.credentialsId refers to an instance of com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl in the system credential store. It has GLOBAL scope and no domain restrictions. The store also contains two credentials of other types but those should not matter here. nfalco , I believe I'll be able to diagnose and fix this issue, but it will take some time because I must not disrupt other users of the Jenkins instance.

          Kalle Niemitalo added a comment - - edited

          The Bitbucket user account used by Jenkins did not have access to the personal fork that was the source of the pull request. I suspect this caused the HTTP 401 error. I have now granted READ access and will test whether it helps. If it does, then I will consider whether I should update the plugin documentation or make the plugin post the build status to the target repository instead.

          Kalle Niemitalo added a comment - - edited The Bitbucket user account used by Jenkins did not have access to the personal fork that was the source of the pull request. I suspect this caused the HTTP 401 error. I have now granted READ access and will test whether it helps. If it does, then I will consider whether I should update the plugin documentation or make the plugin post the build status to the target repository instead.

          Granting READ access helped.

          I think the plugin should be changed to recognize HTTP status 401 and log a message that shows the specific repository on which it needs access and the user account (or credential ID) that it attempted to use.

          Kalle Niemitalo added a comment - Granting READ access helped. I think the plugin should be changed to recognize HTTP status 401 and log a message that shows the specific repository on which it needs access and the user account (or credential ID) that it attempted to use.

            nfalco Nikolas Falco
            kon Kalle Niemitalo
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: