SonarCloud finds files that are not related to a Pull Requests as "new code"

We use SonarCloud integration with Bitbucket and have a build step to stop PRs from getting merged if the coverage on “new code” falls below a certain threshold.

However, we are facing weird behaviours on how sonar finds a diff against the destination branch. SC is finding really old files as having changed (Though it clearly hasn’t and does not show as a difference in bitbucket). We have no workaround for this at the moment.

We are not doing a shallow clone of the repository either as suggested in a couple of other threads.

Is anyone able to help?

  • ALM used - Bitbucket
  • CI system used - GoCD
  • Scanner command used when applicable

/sonar-scanner- -Dsonar.verbose=true -Dsonar.login=__SONAR_LOGIN_CREDS__ -Dsonar.pullrequest.branch=__PROJECT_GIT_BRANCH__ -Dsonar.pullrequest.key=__PROJECT_PR_NUMBER__ -Dsonar.pullrequest.base=__PROJECT_GIT_DEST_BRANCH__

  • Languages of the repository: PHP


Welcome to the community!

Can you provide your job log - redacted as necessary - starting from your checkout and ending with the end of the analysis?


Do you have a way we can share this in private with you? It is a large log and we cannot redact all of it.


I don’t understand. Global copy/paste?


Hey Ann,

Apologies as I may have not been clear. We cannot share the entire log redacted as it is quite a large log and we cannot go line by line to redact it to be posted publicly on a public forum.

Hence, I’m asking if there is a way we can share the log file with Sonar directly.

(post deleted by author)