PR analysis reports not only on changed code against dev-branch

Hi all,

I’m running into an issue with PR analysis in SonarQube Developer Edition and hoping someone has seen this before.

We have SonarQube working as expected on several repos (though all of the uses master as main branch)

The problem:
When I create a PR from a feature branch into dev with a single added line, SonarQube reports ~22,000 “New Lines” instead of the actual change (one line of code). The project has ~10,000 lines on the dev branch that is included in the analysis. SonarQube correctly identifies the PR as “for merge into dev from feature/pr-sonarqube-test”, so the target branch resolution seems correct — but the new code calculation is clearly wrong.

This causes many unrelated issues to be reported against code I haven’t touched.

Setup:

  • Azure DevOps Server (on-premise)
  • SonarQube Developer Edition (on-premise, Kubernetes)
  • The dev branch is both the default branch in Azure DevOps and the Main Branch in SonarQube for the project
  • The dev branch has been analyzed by SonarQube
  • A branch policy on dev triggers a SonarQube quality gate on PRs

What I have already verified:

  • The dev branch new code period is set to “Previous version” in Project Settings → New Code
  • A standalone scan of dev runs on every merge, so the reference snapshot is current
  • The project key (sonar.projectKey) is identical between the branch pipeline and the PR pipeline
  • The dev branch is listed under Project → Branches and Pull Requests with a recent analysis and the correct line count
  • The PR is listed separately and shows the correct base branch

Any pointers would be greatly appreciated. Happy to share pipeline config or scanner logs if that helps.

Thanks!

Hi,

Welcome to the community!

This is going to be about the SCM metadata available to analysis. Make sure the prerequisites are in place.

 
Ann