PR Decoration not showned

Hello,

  • sonarqube-developer-9.0.1.46107
  • PR decoration on Github.com

I’m trying to have PR Decoration on my github.com project threw jenkins.

I follow the tutorial on sonar and configure a new multibranch pipeline project

here is the configuration :

In github i have created an App and gave it the right permisions.

I have had my app to my project and when i pushed on new branch it triggered an analysis on Sonar.

I have change my main branche to feet our repository.

I have created a branch with error in order to test the decoration :

But when i create a Pull Request from this branch i could not see the error :slight_smile:

I check the logs and i found this error :

2021.09.16 09:13:48 INFO ce[AXvt4cdm8_46zkNYNi0t][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Webhooks | globalWebhooks=0 | projectWebhooks=0 | status=SUCCESS | time=123ms
2021.09.16 09:13:48 INFO ce[AXvt4cdm8_46zkNYNi0t][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Pull Request decoration | status=SUCCESS | time=0ms
2021.09.16 09:13:49 WARN ce[AXvt4cdm8_46zkNYNi0t][c.s.F.B.A.B] Failed to access GitHub, the repository or the Pull Request
2021.09.16 09:13:50 WARN ce[AXvt4cdm8_46zkNYNi0t][c.s.F.D.F.J] Branch decoration failed
java.lang.IllegalStateException: Failed to report status to Devops platform: couldn’t get the branch details
at com.sonarsource.F.D.F.J.B(Unknown Source)
at com.sonarsource.F.D.F.J.D(Unknown Source)
at java.base/java.util.Optional.orElseThrow(Optional.java:408)
at com.sonarsource.F.D.F.J.C(Unknown Source)
at com.sonarsource.F.D.F.J.A(Unknown Source)
at com.sonarsource.F.D.F.L.A(Unknown Source)
at com.sonarsource.F.D.l.A(Unknown Source)
at org.sonar.ce.async.SynchronousAsyncExecution.addToQueue(SynchronousAsyncExecution.java:27)
at com.sonarsource.F.D.l.A(Unknown Source)
at java.base/java.util.Optional.ifPresent(Optional.java:183)
at com.sonarsource.F.D.l.finished(Unknown Source)
at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.executeTask(PostProjectAnalysisTasksExecutor.java:110)
at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.finished(PostProjectAnalysisTasksExecutor.java:101)
at org.sonar.ce.task.step.ComputationStepExecutor.executeListener(ComputationStepExecutor.java:91)
at org.sonar.ce.task.step.ComputationStepExecutor.execute(ComputationStepExecutor.java:63)
at org.sonar.ce.task.projectanalysis.taskprocessor.ReportTaskProcessor.process(ReportTaskProcessor.java:81)
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:125)
at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:69)
at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:78)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
2021.09.16 09:13:50 INFO ce[AXvt4cdm8_46zkNYNi0t][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Report branch Quality Gate status to devops platforms | status=SUCCESS | time=1427ms
2021.09.16 09:13:50 INFO ce[AXvt4cdm8_46zkNYNi0t][o.s.c.t.CeWorkerImpl] Executed task | project=Ubble | type=REPORT | branch=20210916_HBI_test_sonar_PR2 | branchType=BRANCH | id=AXvt4cdm8_46zkNYNi0t | submitter=admin | status=SUCCESS | time=26539ms

Could you please help me and tell me what am i doing wrong.

Regards.

Hugo

Hello @hbigot ,

Thanks for the post, pretty exhaustive.
From the logs I suspect that there is something that you have not configured in terms of GitHub integration. Did you do the SonarQube server side configuration as described in GitHub Integration | SonarQube Docs (Setting up your GitHub App, and then importing your repository) ?
If you did, can you show me a screenshot of your GitHub integration in SonarQube (Menu Administration → ALM Integration → GitHub , and then click on “Check configuration”) like below

Hello Olivier,

Thank you for your answer.

I have already configure the alm integration :

In the permissions of the github app i grant access as described in the documentation :

image

Thanks for confirming.
Can you now show me the configuration settings of your project: Browse to Project Settings → General Settings → DevOps platform integration.
Please click on “Check configuration” and take a screenshot, like below.

Here is my configuration :

Hello,

Do you have any updates that could help me with my configutation ?

Regards.

Hello @hbigot ,
Sorry for the delay.
At the moment I have no idea what the problem can be. We’ll have to dig deeper:
Can I ask you to:

  • Activate TRACE logging in the Administration → System Log Level
  • Analyze your PR once again and then send me a zip of your <SONARQUBE_HOME>/logs directory
  • Turn off TRACE logging (very verbose)
  • Send me your Jenkinsfile file for inspection

Hello @OlivierK,

Here is the logs : sonarqube_logs.zip (599.4 KB)

Here is the Jenkinsfile ( i add the .txt extension otherwise i could not upload it here) : Jenkinsfile.txt (203 Bytes)

I see something strange on sonar. On my project when i go to Manage Branches and Pull requests, i see all my branches :

But there is no PRS :

Here is hat i have in github :

It’s a PR but not on the “MAIN” branch. Could it be a problem ?

Regards,

Hugo Bigot

Hello,

No, it does not make any difference. We support decoration for PRs from any branch to any other

That’s clearly abnormal and explains why you have no decoration. For SonarQube the analysis that you do are considered branch analysis and not PR analysis. For branch analysis we make no decoration.

So the problem is (for now) not on the SonarQube server side, but on the Jenkins/Scanner side.
When Jenkins is configured properly, the SonarQube scanner should automatically detect that this is an PR build pipeline, and not a branch build pipeline (even if conceptually that’s close).

I propose to do things in 2 steps:

  • First do a scan outside Jenkins that will show PR decoration as you would expect
  • Then find out what wrong in Jenkins that causes a branch scan instead of a PR scan.

Scanning PR outside of Jenkins:

  • On any machine, download the SonarScanner. Choose the version of scanner for your OS from the download links at the top of this page this page, unzip and add the sonar-scanner executable directory in the PATH
  • In another directory, checkout the repo and the right branch…
  • …then run the scanner
# Clone the repo
git clone <repo_url.git>
# Checkout the right branch (taken from your screenshots)
git checkout 20210916_HBI_test_sonar_PR2
# Run the scanner with the right PR id (#31) and branch name 20210916_HBI_test_sonar_PR2
# Pass your token for auth.
sonar-scanner -Dsonar.pullrequest.key=31 -Dsonar.pullrequest.branch=20210916_HBI_test_sonar_PR2 -Dsonar.host.url=https://sonar.wks-recette.com -Dsonar.login=<YOUR_TOKEN>

The above should hopefully:

  • Show a PR 31 in the pull requests tab in SonarQube
  • Have the PR decorated in GitHub

Finding what’s wrong in the Jenkins configuration
Once the above works, let’s translate that in Jenkins:
I think the problem is the configuration of your multibranch pipeline. For PRs to be detected you have to configure so.
See what described at Jenkins | SonarQube Docs

Let me know if that helps.

Hello,

I did has you said.

Now i see the PR is sonar :

But i don’t understand why is it ok for sonar For me it should fail. Here is the code :

And on github i don’t have any decoration :

Regards

Hello @hbigot,

Let’s not mix topics here: Whether some code should have issue or not is a different problem than decorating the PR (the issues found on a PR are the same as on any branch, and it depends on SonarQube capabilities AND the quality profile that you have chosen AND the quality gate that you have defined). So I’ll defer this discussion.

I can see from your last screenshot that your PR analysis is now well configured (it’s showing in the PR tab in SonarQube). Let’s focus on why the PR is not decorated. Even if there are no issues in the PR, there should be a decoration in GitHub saying “No issues, Quality Gate passed”. It’s apparently not the case. Can you:

  • Show me a full page screenshot of your PR report in SonarQube (select the PR from the branch menu in the project overview) and in particular if there is a warning top right about something that may not have worked as expected, like below. If there is a warning, please click on it and let me know what it says
  • Send me again the full logs of SonarQube (zip of <SONARQUBE_HOME>/logs) since now this is a SonarQube server side problem.

Olivier

Hello,

Here is the screenschot :

And the warning :
image

Here is the log : sonarqube_logs.zip (857.7 KB)

Regards.

Hello @hbigot,
OK, the problem is rather clear from the warning.
For whatever reason SonarQube is unable to detect the SCM used (Git/GitHub) when analyzing the code, and cannot retrieve all the pull request information (SCM revision) to decorate.
Normally this should be auto detected (simply by the presence of a .git directory in the root of your project after checkout in your CI or your local machine).
How do you checkout the code ? git clone/pull/fetch/checkout or something else ?

Hello,

I managed to have the PR decoration usong the command line. (I have to launch it from the git directory)

In Jenkins, i have one last issue.
In my pipeline project i click on "scan repository the PR is detected and i have the decoration in Github but i did not work automatically.

Whein i create the PR in github nothing happened in Github.

Here is my pipeline configuration :

Regards.

In addition, i have this warning on the PR when i triggered it manually from Jenkins :
image

“develop” in the branch in which i wan’t to send my code in the PR

Hello @hbigot ,

Great!

Yes, and that’s not a SonarQube matter. You indeed have to trigger a webhook from GitHub to Jenkins whenever a PR is created OR updated (new code is push on the branch of the PR), and I cannot really help on this. There’s plenty of online help about that if you google github trigger jenkins.
Note that this does not change how SonarQube analyzes or decorates the PR, it’s just about when/how the Jenkins pipeline is triggered.

That is likely related to the fact that SonarQube requires your to perform a full depth git clone in your pipeline (by opposition to a shallow clone), so that all refs can be found locally. See SCM Integration | SonarQube Docs
This is normally the default with multibranch pipelines, but I am not a jenkins expert so that’s something that yous should verify (maybe run git branch as part of your pipeline to visualize all branches fetched locally)

Actually I was able to reproduce the warning on my environment but it seems that this does not prevent the PR to be decorated, in which case I would suggest to ignore the warning. Can you verify that ?

Yes it’s decorated but SoantQube doesn’t found the error i put in the code

I have created in new branch with error.

When i push on github it’s triggered a sonarqube analysis but i have this error :

2021.09.30 13:28:50 WARN ce[AXw25FuHS3oF6En_nfFS][c.s.F.B.A.B] Failed to access GitHub, the repository or the Pull Request
2021.09.30 13:28:50 WARN ce[AXw25FuHS3oF6En_nfFS][c.s.F.D.F.J] Branch decoration failed
java.lang.IllegalStateException: Failed to report status to Devops platform: couldn’t get the branch details
at com.sonarsource.F.D.F.J.B(Unknown Source)
at com.sonarsource.F.D.F.J.D(Unknown Source)
at java.base/java.util.Optional.orElseThrow(Optional.java:408)
at com.sonarsource.F.D.F.J.C(Unknown Source)
at com.sonarsource.F.D.F.J.A(Unknown Source)
at com.sonarsource.F.D.F.L.A(Unknown Source)
at com.sonarsource.F.D.l.A(Unknown Source)
at org.sonar.ce.async.SynchronousAsyncExecution.addToQueue(SynchronousAsyncExecution.java:27)
at com.sonarsource.F.D.l.A(Unknown Source)
at java.base/java.util.Optional.ifPresent(Optional.java:183)
at com.sonarsource.F.D.l.finished(Unknown Source)
at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.executeTask(PostProjectAnalysisTasksExecutor.java:110)
at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.finished(PostProjectAnalysisTasksExecutor.java:101)
at org.sonar.ce.task.step.ComputationStepExecutor.executeListener(ComputationStepExecutor.java:91)
at org.sonar.ce.task.step.ComputationStepExecutor.execute(ComputationStepExecutor.java:63)
at org.sonar.ce.task.projectanalysis.taskprocessor.ReportTaskProcessor.process(ReportTaskProcessor.java:81)
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:125)
at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:69)
at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:78)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
2021.09.30 13:28:50 INFO ce[AXw25FuHS3oF6En_nfFS][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Report branch Quality Gate status to devops platforms | status=SUCCESS | time=1367ms
2021.09.30 13:28:50 INFO ce[AXw25FuHS3oF6En_nfFS][o.s.c.t.CeWorkerImpl] Executed task | project=Ubble | type=REPORT | branch=20210930_sonar4 | branchType=BRANCH | id=AXw25FuHS3oF6En_nfFS | submitter=admin | status=SUCCESS | time=21279ms

Hi @hbigot
We are currently facing the exact same issue as yours. How were you able to get the PR decoration? Could you please elaborate on how you fixed the issue? Appreciate it!