mc1arke / sonarqube-community-branch-plugin

A plugin that allows branch analysis and pull request decoration in the Community version of Sonarqube
GNU Lesser General Public License v3.0
2.26k stars 526 forks source link

Bitbucket PR decorator fails with "key" cannot be more than 50 characters long #897

Open SMUnlimited opened 7 months ago

SMUnlimited commented 7 months ago

Describe the bug Following error occurs after sonar scan on a PR linking to bitbucket. No annotation on the bitbucket PR. Note the scan itself works fine, just the annotation fails with error below. Other repo's and branch PR's seem to work fine.

2024.04.08 14:25:14 ERROR ce[AY6-GUmO7zhALQbf94mo][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Execution of task class com.github.mc1arke.sonarqube.plugin.ce.pullrequest.PullRequestPostAnalysisTask failed
com.github.mc1arke.sonarqube.plugin.almclient.bitbucket.BitbucketException: The field 'key' cannot be more than 50 characters long
at com.github.mc1arke.sonarqube.plugin.almclient.bitbucket.BitbucketServerClient.validate(BitbucketServerClient.java:200)
at com.github.mc1arke.sonarqube.plugin.almclient.bitbucket.BitbucketServerClient.uploadReport(BitbucketServerClient.java:135)
at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.bitbucket.BitbucketPullRequestDecorator.decorateQualityGateStatus(BitbucketPullRequestDecorator.java:96)
at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.PullRequestPostAnalysisTask.finished(PullRequestPostAnalysisTask.java:138)
at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.executeTask(PostProjectAnalysisTasksExecutor.java:102)
at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.finished(PostProjectAnalysisTasksExecutor.java:93)
at org.sonar.ce.task.step.ComputationStepExecutor.executeListener(ComputationStepExecutor.java:89)
at org.sonar.ce.task.step.ComputationStepExecutor.execute(ComputationStepExecutor.java:61)
at org.sonar.ce.task.projectanalysis.taskprocessor.ReportTaskProcessor.process(ReportTaskProcessor.java:75)
at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.executeTask(CeWorkerImpl.java:212)
at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.run(CeWorkerImpl.java:194)
at org.sonar.ce.taskprocessor.CeWorkerImpl.findAndProcessTask(CeWorkerImpl.java:160)
at org.sonar.ce.taskprocessor.CeWorkerImpl$TrackRunningState.get(CeWorkerImpl.java:135)
at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:87)
at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:53)
at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:131)
at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:74)
at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:82)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)

To Reproduce Not sure what key specifically is too long, but I suspect the report key itself is over 50 characters? I guess this is not configurable in uploadReport method.

Looks like this is just ultimately the project key, which yes the project key is over this many characters as its a maven project so automatically pulls in the groupId:artifactId which can be long.

Expected behavior PR annotation occurs, or it does not but we can configure the report key as part of the scan so it comes under this limit.

Software Versions

Workaround We can override the project key using sonar.projectKey property, after using the sonar UI "Project Settings -> Update Key" to change the project key to desired shorter ID.

mc1arke commented 7 months ago

What length is your project key on an impacted project? Sonarqube project IDs (as sent to Bitbucket) are based on the project name plus a homegrown UUID-style identifier (this switched to an actual UUID in 10.4)

SMUnlimited commented 7 months ago

Sonar Project Key: 66

Broken down into the maven properties sonar auto creates project key from: GroupId: 40 ArtifactId: 25

SMUnlimited commented 6 months ago

Note sonar UI says project key is legitimately allowed to be up to 400 characters long.