SonarCloud PR analysis creates issues for non-new code lines within changed files

Hi,
In SonarCloud Pull Request analysis, the report generates issues for lines that are not part of the new code and are unrelated to the actual changes.

The analysis correctly scopes itself to only the files modified in the pull request. However, for those files, SonarCloud produces issues for all lines in the file, not just the lines changed in the PR.

What I want to achieve is:

  • Generating a report that includes only new/changed code, or

  • Getting separate results for New Code and Overall Code, similar to how branch analysis works in SonarCloud.

Is it possible to configure SonarCloud PR analysis to behave this way, or to restrict issue creation strictly to new code only?

Thanks in advance for your help.

Details:

  • pipeline runs via pull request from azure devops to run sonar analyse

  • Provider is set to “Azure Devops Services” and from sonarcloud console. General Settings → Pull Requests → Provider

  • Personal Access Token set from sonar cloud console. General Settings → Pull Requests → Provider

  • pipeline includes the tasks below

    • SonarCloudPrepare@3
    • Gradle@4
      inputs:
      gradleWrapperFile: ‘gradlew’
      tasks: ‘clean assembleProdDebug’
      publishJUnitResults: true
      javaHomeOption: ‘JDKVersion’
      sonarQubeRunAnalysis: true
      sqGradlePluginVersionChoice: ‘specify’
      sonarQubeGradlePluginVersion: ‘5.1.0.4882’
      spotBugsAnalysis: false
    • SonarCloudPublish@3

Hi,

PR analysis in SonarQube Cloud reports all issues that are new in the file versus the baseline branch. Has that baseline branch been analyzed recently? If not, that could be the source of the problem.

The fact that only the relevant files get issues make me think it’s not about the SCM data relevant to analysis. That was likely all present and correct.

 
Ann

Hi Ann,

Thanks for the clarification.

You’re right — the baseline branch hasn’t been analyzed recently. Does this cause SonarCloud to report issues for the entire file instead of only the changed lines?

We’ll run a new analysis on the baseline branch and verify whether the PR analysis behaves as expected afterward.

Appreciate the help.

Hi,

In this context every issue that hasn’t been found in the branch yet will be shown in the PR. Across the whole file.

 
HTH,
Ann