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.22k stars 521 forks source link

Azure DevOps files comments not appear #715

Closed daominhsangvn closed 1 month ago

daominhsangvn commented 1 year ago

Describe the bug Azure DevOps files comment not appear

To Reproduce Steps to reproduce the behavior:

  1. Create a Pull Request with the code smell changes

Expected behavior Code smells comments from the SonarQube should be added to the Azure DevOps

Screenshots image image image

Software Versions

Additional context

mareksabo commented 1 year ago

We had similar issue in our project, only summary without individual comments. The problem was in the setup, Administration -> ALM Integrations -> GitLab URL (sonar.auth.gitlab.url) needs to be https://gitlab.com/, not https://gitlab.com/api/v4/.

I was able to make it work on older sonar version 8.9.6. with plugin version 1.8.1

robbertvanstaveren commented 1 year ago

I am having the same issue. I am using the latest community LTS version of SonarQube (9.9) and plugin version 1.14. I am getting the summary but no comments on the PR in Azure DevOps.

mc1arke commented 1 year ago

Please provide a copy of your compute engine logs for a scan that fails to add file comments if you're encountering this issue, obfuscating any sensitive file names or code, and any URLs, but ensuring the general message structure remains in place.

bambuca commented 1 year ago
2023.08.18 09:50:56 INFO  ce[AYoIDhBXCt_uzGaS79uf][c.g.m.s.p.c.p.PullRequestPostAnalysisTask] Using pull request decorator com.github.mc1arke.sonarqube.plugin.ce.pullrequest.azuredevops.AzureDevOpsPullRequestDecorator
2023.08.18 09:50:56 ERROR ce[AYoIDhBXCt_uzGaS79uf][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Execution of task class com.github.mc1arke.sonarqube.plugin.ce.pullrequest.PullRequestPostAnalysisTask failed
java.lang.IllegalArgumentException: Cannot format given Object as a Number
    at java.base/java.text.DecimalFormat.format(Unknown Source)
    at java.base/java.text.Format.format(Unknown Source)
    at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.report.AnalysisSummary.format(AnalysisSummary.java:212)
    at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.azuredevops.AzureDevOpsPullRequestDecorator.submitSummaryNote(AzureDevOpsPullRequestDecorator.java:177)
    at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.azuredevops.AzureDevOpsPullRequestDecorator.submitSummaryNote(AzureDevOpsPullRequestDecorator.java:63)
    at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.DiscussionAwarePullRequestDecorator.decorateQualityGateStatus(DiscussionAwarePullRequestDecorator.java:105)
    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)
2023.08.18 09:50:56 INFO  ce[AYoIDhBXCt_uzGaS79uf][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Pull Request Decoration | status=FAILED | time=407ms
2023.08.18 09:50:56 INFO  ce[AYoIDhBXCt_uzGaS79uf][o.s.c.t.CeWorkerImpl] Executed task | project=ServiceRequest | type=REPORT | pullRequest=26997 | id=AYoIDhBXCt_uzGaS79uf | submitter=jan-nielsen75892 | status=SUCCESS | time=1585ms
bambuca commented 1 year ago

My error was caused by "The main branch has no lines of code.". I have fixed it by adding

  <PropertyGroup>
    <!-- Project is not a test project -->
    <SonarQubeTestProject>false</SonarQubeTestProject>
  </PropertyGroup>

to all csproj files (see https://improveandrepeat.com/2023/02/how-to-fix-a-project-with-0-lines-of-code-in-sonarqube/).

ThomGeG commented 11 months ago

I was having the same problem with Azure DevOps (Sonar leaving a summary comment, but no individual comments per issue) but I figured it out and thought I'd leave a comment.

In my case I was doing an analysis myself on some additional changes I hadn't committed & pushed yet. The logs didn't contain any errors and the debug logging wasn't indicating any attempt to leave individual comments. After trawling through the source code I found found this:

https://github.com/mc1arke/sonarqube-community-branch-plugin/blob/587442498498dc32f7cde85375cb35a46a866a0f/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/DiscussionAwarePullRequestDecorator.java#L88-L95

The plugin won't actually leave comments on issues that don't belong to commits reachable from the pull request. Sonar will happily report on them itself if they meet whatever you've configured 'New Code' to mean, however there's filtering logic in the plugin that prevents them carrying through into the PR decoration.

Hope that helps any future travellers who were similarly confused.

s0lidcloud commented 3 months ago

@mc1arke the same issue

2024.07.16 18:06:47 ERROR ce[AZC8ubgdZn2EYqCyzd_D][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Execution of task class com.github.mc1arke.sonarqube.plugin.ce.pullrequest.PullRequestPostAnalysisTask failed
java.lang.IllegalArgumentException: Cannot format given Object as a Number
    at java.base/java.text.DecimalFormat.format(Unknown Source)
    at java.base/java.text.Format.format(Unknown Source)
    at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.report.AnalysisSummary.format(AnalysisSummary.java:212)
    at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.azuredevops.AzureDevOpsPullRequestDecorator.submitSummaryNote(AzureDevOpsPullRequestDecorator.java:177)
    at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.azuredevops.AzureDevOpsPullRequestDecorator.submitSummaryNote(AzureDevOpsPullRequestDecorator.java:63)
    at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.DiscussionAwarePullRequestDecorator.decorateQualityGateStatus(DiscussionAwarePullRequestDecorator.java:105)
    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)

https://github.com/mc1arke/sonarqube-community-branch-plugin/blob/7499112f133cceca3acf7738ffbc8c29379eae20/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/report/AnalysisSummary.java#L212

Related to this: https://github.com/mc1arke/sonarqube-community-branch-plugin/issues/335#issuecomment-1219114717 (#335)

There were changes only in the jenkins files.

SonarQube: v9.9.5 (build 90363), Plugin: 1.14.0

mc1arke commented 1 month ago

Released in 1.22.0