Sometimes sonarqube doing analysis on legacy code even though we have defined as to consider 'New Code'

Hi Team,
We are using Sonarqube oss 8.6 and scanner 2.13 and jenkins version is 2.176.

We have defined Quality Gate on ‘New code’ and also ‘New code’ behaviour is defined as ‘Previous Version’(default).We have configured in such away that every build is consider as a New code.
Sometimes ‘Issues’ of the current build are showing on Legacy code(overall code) and issues are assigning to ‘unknown user/someother developer name’ which are not at all related to current developer changes.But we see the correct number of lines/file name under the ‘Overview’ project page of ‘Duplication on 28 lines’(If you click on 28, in the next page we can see the details).We are pushing the code to jenkins from Gerrit and jenkins job will trigger automatically once code pushed to gerrit. We are using Jira for issue management.
Could you please let me know how to overcome this issue.


Must-share information (formatted with Markdown):

  • which versions are you using :SonarQubue commutniy edition 8.6
  • what are you trying to achieve: Sonar has to analysis source code based on ‘New code’ concept.
  • what have you tried so far to achieve this: Defined analysis to consider ‘Newcode’ based on ‘previous commit’ instead of ‘Overall code’. and we are pushing code to gerrit so that jenins job will trigger automatically. We configured in such a way that every push can be consider as ‘New code’ so that one developer code push is independent of other developer code push.
    Sometimes analysis happening correctly and issues are displaying on New code and same issues are assigned to developer name who has pushed the code (we are using JIRA).But some times it’ s not happening. That means analysis is happening on the other files/legacy code which are not modified by current build developer and also issues details are assigning to some other developer. If you push the same code again happening correctly. Not sure what is the mistake here.
    Could you please let me know why this is happening. How to overcome this issue.



Analysis is always going to include every file. In some situations, new issues are only reported on updated code.

It’s possible that changes in file, or method, or even line A will trigger new issues in B, which was unmodified. The easiest example of that is removing the only use of a private variable. The variable declaration has not changed but suddenly there’s a new issue on it. I.e. the behavior you describe is expected.