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:
and main sonar-project.properties:
Full path to file:
Move your main sonar-project.properties file from ./src/ to ./, change sonar-project.properties into:
AND 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.