Issues on unchanged lines in pull request after merging of different branch

we recently switched to the dotnet-sonarscanner in our project, because we want to analyse solutions containing c# and c++ code. At the same time, we also made the switch from Jenkins to gitlab ci/cd to run our analysis.
We noticed, that the pull request analysis now detects problems for lines which are not changed in the current branch.

Example to reproduce:

  • branches: main (, branch1, branch2)
  • create analysis on “main”
  • create branch 1 from main => changes => analysis on pull request works
  • create branch 2 from main => changes => analysis on pull request works
  • merge branch 1 into main, but do not start new analysis on main branch, delete branch 1
  • more changes on branch 2 => run analysis on branch2 pull request=> analysis contains changes from branch1 and branch2. Issues for branch2 pull request not only on changes made in this branch.

Is there an obvious fix for this? I read that scanners automatically detect pull request parameters when running GitLab CI and we are also seeing that its a pull request analysis on the sonarqube page as there is a link to the pull request (see picture below) and the url contains “…&pullRequest=XXXX”.

  • Enterprise Edition, Version 9.5 (build 56709)
  • dotnet-sonarscanner 5.8


I guess branch1 introduces new issues into main? And I also guess there’s a rebase of branch2 on the updated main in there?

We did some work earlier in the series around mis-labeled issues after a rebase. You’re not on the latest version, but I’m pretty sure they took place before 9.5.

At the same time, I’m kinda stuck on this:

Why would your pipeline not be set up to automatically reanalyze main after any change? As-is, your branch2 analysis is the first time SonarQube is seeing the issues introduced into main from branch1.

I suggest two things:

  • upgrade to the latest version, 9.7.1 (9.8 due “soon”)
  • reanalyze main after each change

If you’re still seeing the problem after those changes, please do come back and let us know.


1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.