AmadeusITGroup / sonar-stash

Stash (BitBucket) plugin, a pull-request decorator which allows to integrate SonarQube violations directly into your pull-request
MIT License
165 stars 81 forks source link

Plugin finds no issues in analysis.mode publish #129

Closed petterm closed 7 years ago

petterm commented 7 years ago

I have a setup with Bitbucket server, Jenkins and SonarQube running and had a stab att getting them integrated together.

A problem I got into was that even though the analysis works fine when looking in the SonarQube project I couldn't get the stash plugin to post anything else than that it found no new issues.

I looked through the issues reported here and started out by building the 1.3-SNAPSHOT from pull-request #127 although that did not seem to fix my issue (I do still use it though since I probably would end up with the resource keys being a problem down the line). I continued troubleshooting and added some logging to the plugin to check that it actually received any issues.

Added inside StashIssueReportingPostJob executeOn

  @Override
  public void executeOn(Project project, SensorContext context) {
    if (!config.hasToNotifyStash()) {
      LOGGER.info("{} not enabled, skipping", this);
      return;
    }
    List<Issue> issues = StreamSupport.stream(
                         projectIssues.issues().spliterator(), false)
                        .collect(Collectors.toList());
    LOGGER.info("{} issues", issues);
    ...

Using that I concluded that no issues were received by the plugin at all.

09:19:59.717 DEBUG: Post-jobs : org.sonar.plugins.stash.StashIssueReportingPostJob@19dc0d32
09:19:59.717 INFO: Executing post-job org.sonar.plugins.stash.StashIssueReportingPostJob
09:19:59.890 INFO: [] issues

Further research led me to issue #43 that looked much like my problem. When testing out the suggestion there i set sonar.analysis.mode=preview and now the plugin receives issues and I get comments working.

This should be enough for my setup to work but it means I will have to run the analysis twice to get issues both into Bitbucket and to SonarQube though.

t-8ch commented 7 years ago

Hi @petterm, which version of SonarQube are you using? If we don't get the data from sonarqube there is not much we can do -.-

t-8ch commented 7 years ago

From https://docs.sonarqube.org/display/DEV/Adding+Hooks :

when the scanner sends the raw report to Compute Engine. The extension point org.sonar.api.batch.postjob.PostJob must be implemented. It is executed whatever the scanner mode ("preview" or not). List of open and resolved issues is available only if the mode "preview" is enabled. Measures and Quality gate can not be accessed, whatever the mode.The GitHub and Bitbucket plugins rely on this extension point.

petterm commented 7 years ago

So you are saying it is working as intended then? If so that seems like something that should be in the documentation for this plugin?

Im running the following it that is still of interest: SonarQube: Version 6.3.1 Jenkins: Version 2.32.3 SonarQube Scanner for Jenkins: Version 2.6

t-8ch commented 7 years ago

Yes, this is working as intended by SonarQube. I don't think there is anything we can do about this (with reasonable effort). I think this should be documented on SonarQube side, as it affects all plugins implemented as PostJobs.

It is currently documented but I agree that the location is not really obvious. It should be documented with the different publishing modes.

petterm commented 7 years ago

I did see now that you do mention it in the docs for this plugin as well. Might be that I just missed it but it seems easy to miss.

https://github.com/AmadeusITGroup/sonar-stash#how-to-run-the-plugin

For SonarQube 5.2+:

sonar-runner -Dsonar.analysis.mode=preview \
-Dsonar.stash.notification=true -Dsonar.stash.project=<PROJECT> -Dsonar.stash.repository=<REPO> \
-Dsonar.stash.pullrequest.id=<PR_ID> -Dsonar.stash.password=<STASH_PASSWORD>...

Thanks for the assistance either way.