bitbucket-branch-source-plugin icon indicating copy to clipboard operation
bitbucket-branch-source-plugin copied to clipboard

Issue updating Build Status for long fields

Open andrewandante opened this issue 5 years ago • 5 comments

Your checklist for this issue

  • [x] Jenkins version 2.150.2

  • [x] Plugin version 2.4.1

  • [X] Bitbucket cloud

Description

A few of our builds are throwing the following error on completion:

[Bitbucket] Notifying pull request build result

ERROR: Could not send notifications

com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRequestException: HTTP request error. Status: 400: Bad Request.

HttpResponseProxy{HTTP/1.1 400 Bad Request [Server: nginx, Vary: Authorization, Content-Type: application/json; charset=utf-8, X-OAuth-Scopes: webhook, issue:write, pullrequest:write, project, team, account, Strict-Transport-Security: max-age=31536000; includeSubDomains; preload, Date: Tue, 21 May 2019 10:07:51 GMT, X-Served-By: app-143, ETag: "1a7f341ee7c5d710e4b32329f8c15df2", X-Static-Version: 83e77132b252, X-Accepted-OAuth-Scopes: repository, X-Credential-Type: apppassword, X-Render-Time: 0.235884189606, Connection: close, X-Request-Count: 627, X-Frame-Options: SAMEORIGIN, X-Version: 83e77132b252, Content-Length: 191] ResponseEntityProxy{[Content-Type: application/json; charset=utf-8,Content-Length: 191,Chunked: false]}}

	at com.cloudbees.jenkins.plugins.bitbucket.client.BitbucketCloudApiClient.doRequest(BitbucketCloudApiClient.java:851)

	at com.cloudbees.jenkins.plugins.bitbucket.client.BitbucketCloudApiClient.postRequest(BitbucketCloudApiClient.java:901)

	at com.cloudbees.jenkins.plugins.bitbucket.client.BitbucketCloudApiClient.postBuildStatus(BitbucketCloudApiClient.java:606)

	at com.cloudbees.jenkins.plugins.bitbucket.BitbucketChangesetCommentNotifier.buildStatus(BitbucketChangesetCommentNotifier.java:50)

	at com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications.createStatus(BitbucketBuildStatusNotifications.java:138)

	at com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications.sendNotifications(BitbucketBuildStatusNotifications.java:163)

	at com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications.access$000(BitbucketBuildStatusNotifications.java:59)

	at com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications$JobCompletedListener.onCompleted(BitbucketBuildStatusNotifications.java:221)

	at hudson.model.listeners.RunListener.fireCompleted(RunListener.java:211)

	at org.jenkinsci.plugins.workflow.job.WorkflowRun.finish(WorkflowRun.java:586)

	at org.jenkinsci.plugins.workflow.job.WorkflowRun.access$900(WorkflowRun.java:133)

	at org.jenkinsci.plugins.workflow.job.WorkflowRun$GraphL.onNewHead(WorkflowRun.java:998)

	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.notifyListeners(CpsFlowExecution.java:1452)

	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$3.run(CpsThreadGroup.java:435)

	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$1.run(CpsVmExecutorService.java:35)

	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)

	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)

	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)

	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

	at java.util.concurrent.FutureTask.run(FutureTask.java:266)

	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

	at java.lang.Thread.run(Thread.java:748)

Finished: SUCCESS

But not all of them. They are all linked with a particular PR, where the branch name is long (73 chars) and the branch description is even longer (243 chars) - so I suspect this is the issue. However, it would be good if this was truncated before being sent to the BitBucket API, as we have merge checks enabled and can't proceed without build successes.

I'm not sure what the actual limit is, can't find any docs from Atlassian, but I did find this at https://docs.atlassian.com/bitbucket-server/rest/6.3.0/bitbucket-build-rest.html:

All fields (mandatory or optional) are limited to 255 characters, except for the url, which is limited to 450 characters.

~Which doesn't quite add up to what I was saying above, but I wonder if there's some prefixing/suffixing going on or something.~

It does add up when you add the prefix <pipeline name> » <pull request id>

andrewandante avatar May 21 '19 11:05 andrewandante

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 20 '19 12:07 stale[bot]

Hello, This error is still there and doesn't seems to have been fixed yet. The error seems to appears for some branches only, and could effectively come from the length of the branch name/description.


[Bitbucket] Notifying commit build result
ERROR: Could not send notifications
com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRequestException: HTTP request error. Status: 400: .

HttpResponseProxy{HTTP/1.1 400  [Server: nginx, Date: Wed, 24 Nov 2021 13:52:46 GMT, Content-Type: application/json;charset=UTF-8, Transfer-Encoding: chunked, Connection: keep-alive, X-AREQUESTID: @3YQ3S5x892x105860x0, X-AUSERID: 18919, X-AUSERNAME: wam_jenkins, Cache-Control: no-cache, no-transform, Vary: x-ausername,x-auserid,cookie,accept-encoding, X-Content-Type-Options: nosniff] org.apache.http.client.entity.DecompressingEntity@118ac94e}
	at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.doRequest(BitbucketServerAPIClient.java:1095)
	at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.postRequest(BitbucketServerAPIClient.java:1048)
	at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.postRequest(BitbucketServerAPIClient.java:1036)
	at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.postBuildStatus(BitbucketServerAPIClient.java:511)
	at com.cloudbees.jenkins.plugins.bitbucket.BitbucketChangesetCommentNotifier.buildStatus(BitbucketChangesetCommentNotifier.java:50)
	at com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications.createStatus(BitbucketBuildStatusNotifications.java:161)
	at com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications.sendNotifications(BitbucketBuildStatusNotifications.java:203)
	at com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications.access$100(BitbucketBuildStatusNotifications.java:59)
	at com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications$JobCompletedListener.onCompleted(BitbucketBuildStatusNotifications.java:285)
	at hudson.model.listeners.RunListener.fireCompleted(RunListener.java:208)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.finish(WorkflowRun.java:625)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.access$800(WorkflowRun.java:138)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun$GraphL.onNewHead(WorkflowRun.java:1045)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.notifyListeners(CpsFlowExecution.java:1473)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$3.run(CpsThreadGroup.java:491)
	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$1.run(CpsVmExecutorService.java:38)
	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

danjor avatar Nov 24 '21 14:11 danjor

Issue still exists. Occured on

  • [x] Jenkins 2.387.3

  • [x] Bitbucket Server v8.10.0

  • [x] Bitbucket Branch Source Plugin 804.v8b_0642650b_d2

optica-phoffmann avatar Dec 01 '23 14:12 optica-phoffmann

Is there any documentation on how long strings the Bitbucket API allows? Alternatively, can someone test it?

I would not assume that Cloud and Server have the same limits.

KalleOlaviNiemitalo avatar Dec 01 '23 14:12 KalleOlaviNiemitalo

I did some tests. On Bitbucket Server Pull Request titles are limited to 256 characters. I was able to create Pull Request with titles of up to 234 characters without Notification errors in Jenkins. In the range between 234 and 256 characters the api errors start to appear.

It seems odd to me that the whole PR title must be transferred via API when notifying Bitbucket PR from Jenkins. Bitbucket already knows the title of the PR. Repo ID and PR ID should be sufficient, right?

optica-phoffmann avatar Dec 01 '23 15:12 optica-phoffmann