Stash-plugin-issues

In my current Hybris project one of coding standard is to publish SonarQube report before every push to master. This rule is nice, but not always everyone fallows it.

This is why I’ve wanted to introduce plugin that can automatically generates SonarQube analysis results in BitBucket (Stash) pull-request. And I’ve found it: SonarQube Stash (BitBucket) plugin.

The workflow looks as fallow:

user creates pull-request 
-> hook executes Jenkins job 
-> sonar-scanner executes analysis in preview mode 
-> Executing post-job org.sonar.plugins.stash.StashIssueReportingPostJob
-> SonarQube analysis overview has been reported to Stash.

It’s almost perfect, but instead of comments in lines with violations I get a lot of messages like this:

Comment "squid:S1134" cannot be pushed to Stash like it does not belong to diff view - nc3cockpit/src/com/nespresso/nc3/cockpit/components/header/Nc3LeftSectionHeaderComponent.java (line: 14)

How to fix “Comment cannot be pushed to Stash like it does not belong to diff view”

In my case the problem was with project configuration. Analysed code was in different location then GIT root directory:

/
/README.md
/src
/src/sonar-project.properties
/src/lib
/src/lib/sonar-project.properties
/src/web
/src/web/sonar-project.properties
/docs

Similar structure can be checked here: https://github.com/kirkor/sonar-stash-test-project/tree/0646de81f2424061ff2deaeec4899ee4cd356cbb

Note that I’m referring to old version of this repo where this problem exists. In the newest revision whole project is configured in a way that problem “Comment cannot be pushed” is not occurring.

I’m executing sonar-scanner from Jenkins, so the working directory is ./ instead of ./src/. This is why my command was like this:

sonar-scanner sonar.projectBaseDir=./src/

and main sonar-project.properties:

sonar.modules=lib,webapp

Results

Full path to file:

E:/Jenkins/workspace/CI03/src/lib/src/main/java/pl/com/bernas/sonar/stash/test/lib/DummyService.java

Output:

./lib/src/main/java/pl/com/bernas/sonar/stash/test/lib/DummyService.java

Should be:

./src/lib/src/main/java/pl/com/bernas/sonar/stash/test/lib/DummyService.java

The Fix

Move your main sonar-project.properties file from ./src/ to ./, change sonar-project.properties into:

sonar.modules=src/lib,src/webapp

execute command:

sonar-scanner sonar.projectBaseDir=./

AND IT’S WORKING :)

Stash-plugin-task

During development of my fix PR#56 (which is not need eventually), I created GIT repo to test the solution. If you fallow those two links you can find some more interesting things how it’s working.

And it’s all started from Issue: Comment “xxx” cannot be pushed to Stash like it does not belong to diff view.

Wczoraj założyłem sobie płatne konto na GitHub’ie, aby mój projekt edukacyjny (pisany w Symfony 1.4) posiadał kontrolę wersji – po za tym przyda mi się to w pracy zawodowej. Wcześniej używałem SVN lub CVS, i w zasadzie zupełnie przez przypadek zacząłem używać GIT’a. Skusił mnie głównie GitHub, który zajmuje się hostingiem repozytoriów – koniec z utrzymywaniem własnego serwera. Trafiłem tam przy okazji czytania na temat Warszawa JUG (http://github.com/warszawajug). Przyjrzałem się dokładniej GitHub’owi i bardzo mi się on spodobał.Continue reading