How to disable SonarScanner post job action for the Sonar Bitbucket Cloud plugin

700 views Asked by At

After completion of the SonarScanner analysis, there's some post-job running as below:

[DEBUG] 14:56:53.076 Post-jobs : Sonar Plug-in for Bitbucket Cloud
[INFO] 14:56:53.076 Executing post-job 'Sonar Plug-in for Bitbucket Cloud'

This fails when I have binary files in the PR with the below message:

diff --git a/docs/folder1/images/image.png b/docs/folder1/images/image.png
new file mode 100644
index 0000000..c73bf4c
Binary files /dev/null and b/docs/folder1/images/image.png differ
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project demo-proj: [sonar4bitbucket] Failed to parse diff: string matching regex `\z' expected but `B' found -> [Help 1]

One of the solutions is listed here. But this is not feasible and I want to skip the post-job completely. This is the content of sonar-maven-plugin plugin in my pom.xml file currently -

<plugin>
  <groupId>org.sonarsource.scanner.maven</groupId>
  <artifactId>sonar-maven-plugin</artifactId>
  <version>3.7.0.1746</version>
  <executions>
    <execution>
      <phase>install</phase>
      <goals>
        <goal>sonar</goal>
      </goals>
    </execution>
  </executions>
</plugin>

If the goal org.sonarsource.scanner.maven is causing this, I would just like to disable this. Is there a way I can achieve this?

1

There are 1 answers

0
agabrys On BEST ANSWER

The issue come from the Sonar Plug-in for Bitbucket Cloud plugin. SonarScanner is failing because it is forced to do it by the plugin.

I checked the issue which you linked. The most important part of the stacktrace:

java.lang.RuntimeException: [sonar4bitbucket] Failed to parse diff: string matching regex \z' expected but F' found
at ch.mibex.bitbucket.sonar.diff.IssuesOnChangedLinesFilter.parseOrFail(IssuesOnChangedLinesFilter.scala:54)
at ch.mibex.bitbucket.sonar.diff.IssuesOnChangedLinesFilter.filter(IssuesOnChangedLinesFilter.scala:16)
at ch.mibex.bitbucket.sonar.review.ReviewCommentsHandler.processIssues(ReviewCommentsHandler.scala:96)
at ch.mibex.bitbucket.sonar.review.ReviewCommentsHandler.updateComments(ReviewCommentsHandler.scala:33)
at ch.mibex.bitbucket.sonar.review.SonarReviewPostJob.ch$mibex$bitbucket$sonar$review$SonarReviewPostJob$$handlePullRequest(SonarReviewPostJob.scala:45)
[...]

I checked the mentioned classes (SonarReviewPostJob and ReviewCommentsHandler) and I don't see any way to disable this processor.

The last release of the plugin was on the 18th of December 2017. I don't see any active development on it too (last commit was 2 years ago - 31 May 2019). I found a commit which added support for SonarQube 6.5+, but it has been not releases (26th January 2019). Finally, the README.md file of the not released changes informs:

The plug-in only supports SonarQube versions < 7.7 due do the required preview mode

It means it doesn't support SonarQube 7.X LTS. SonarSource is going to release 8.X LTS within a few months (it should be between Febtuary-April 2021).

In my opinion the only way to solve the problem is to uninstall the unmaintained plugin. At this moment it fails on binary files, but soon you would start hitting NoClassDefFoundError (e.g. when your SonarQube instance is updated).