SonarCloud Pull request analysis, analyses changes that were not made within PR

  • ALM used: GitHub
  • CI system used: Jenkins
  • Languages of the repository: Java

Sonar scan configuration:
'sonar.pullrequest.branch= ${sha1}
'sonar.pullrequest.key=${ghprbPullId}
"sonar.pullrequest.github.repository= organization/${pServiceName}
'sonar.pullrequest.provider=GitHub
'sonar.pullrequest.base=${ghprbTargetBranch}

For some reason, sonar is analyzing (Pull request analysis), extra new code that was not made in this certain PR.

For example, there was a change made in Main.class(one line) and sonar is showing that there are 240 lines of new code.

Do anyone know what might be the reason?

Hey there.

You don’t want to put a commit hash here – but probably something closer to ghprbSourceBranch or GIT_BRANCH

Hi Colin,
I’ve changed this parameter to ghprbSourceBranch and still,
after I do PR with changes in two classes(a few lanes changed), Sonar is detecting 417 new lines of code in multiple classes.

Screenshot 2022-03-10 at 13.58.40
Screenshot 2022-03-10 at 13.59.01

Additionally, what I observed, PR analysis is showing new lines of code that were already merged to master 1/2 days ago. I’ve verified all parameters and everything is set correctly.

Do you have any idea what might be the reason?

Analysis was run using these properties:

Project scanner properties:

  • sonar.projectKey=repo_key
  • sonar.pullrequest.base=develop
  • sonar.pullrequest.branch=FUL-XXXX
  • sonar.pullrequest.github.repository=repo
  • sonar.pullrequest.key=691
  • sonar.pullrequest.provider=GitHub

Sonar is showing the right PR, but the new lines are not matching with certain PR

I hava the same issue, does anyone have resolved the problem, thank you for your solutions.