New Code always 0 for PRs – Issues detected only after PR is merged in Azure DevOps

that’s the version of DevOps Task

  • task: DotNetCoreCLI@2
    displayName: ‘Build Solution’
    inputs:
    command: ‘build’
    projects: ‘$(solution)’
    arguments: '–configuration $(buildConfiguration)
1 Like

Hi,

Okay, thanks.

I’m not sure what else to look at here, so I’m going to flag this for more expert eyes.

 
Ann

please let me know if i need to provide more details/logs

1 Like

Hi @user9

Sorry for the delay, we are trying to catch up with this long thread.

One element that could cause such issues is invalid branch or PR analysis configuration. I saw in one snippet you shared earlier that you are manually passing:

sonar.pullrequest.branch=$(System.PullRequest.SourceBranch)

This is probably wrong, as the System.PullRequest.SourceBranch value looks like refs/heads/users/raisa/new-feature while we expect users/raisa/new-feature.

The SonarQube AzureDevops extension should already provide those parameters correctly, so I would recommend to remove any parameter overrides you may have defined, and try again.

Hi

Yes, we had that at one time when I was trying to fix this issue myself.
Latest run on May 8, I didn’t have that in the task.
It was then:

  • task: SonarQubePrepare@7
    displayName: ‘Prepare analysis on SonarQube’
    inputs:
    SonarQube: ‘SonarQube’
    scannerMode: ‘dotnet’
    projectKey: ‘projKey’
    projectName: ‘projName’
    extraProperties: |
    sonar.scm.provider=git
    sonar.scm.exclusions.disabled=true
    sonar.verbose=true

i updated it today to:

  • task: SonarQubePrepare@7
    displayName: ‘Prepare analysis on SonarQube’
    inputs:
    SonarQube: ‘SonarQube’
    scannerMode: ‘dotnet’
    projectKey: ‘projKey’
    projectName: ‘projName’
    extraProperties: |
    sonar.verbose=true

still same result, the PR shows 0 new lines of code in sonarqube dashboard.

Sorry if this sounds like repeating yourself, but for your last “clean” (ie without manual properties) attempt, can you tell me:

  • what are the PR source branch and target branch, in your ALM (GitHub or Azure Devops)?
  • what are the source and target branch detected by SonarQube (you can see that in the UI)

Then I would like the more recent verbose logs of the SonarQubeAnalyze step. What is very interesting is this log:

[INFO] SCM collecting changed files in the branch
[INFO] Merge base sha1: 0aced38d0b5130d8c7ebd269a61ca41e874fa776
[INFO] SCM collecting changed files in the branch (done) | time=128ms

as the detection of changed files will basically do a diff between the current commit and the merge base sha1.

Source branch test-5.24
Target branch 5.23
We use Azure DevOps

In SonarQube dashboard: for merge into 5.23 from test-5.24

Attached is log of the latest run of the PR.
SonarQubeAnalyzeLog20250605.2.txt (1.3 MB)

Hi @user9

2025-06-05T17:10:46.7767985Z 17:10:46.775 INFO: SCM revision ID '9198401ac55ae7611fa75f155b622f2001451c6b'
2025-06-05T17:10:47.0116582Z 17:10:47.010 INFO: SCM writing changed lines
2025-06-05T17:10:47.0307974Z 17:10:47.029 INFO: Merge base sha1: a42c0730f467f401fea62efb6f197d9e60d7740a
2025-06-05T17:10:47.0314984Z 17:10:47.030 DEBUG: SCM reported changed lines for 0 files in the branch

are the hashes consistent with what you would expect? I think 9198401ac55ae7611fa75f155b622f2001451c6b should be test-5.24 and a42c0730f467f401fea62efb6f197d9e60d7740a should be 5.23.

What do you get in Git if you run:

git diff 9198401ac55ae7611fa75f155b622f2001451c6b a42c0730f467f401fea62efb6f197d9e60d7740a