Short Lived Branch Analysis Does Not Work using Azure Dev Ops

I am using the Azure Dev Ops SonarCloudAnalyze and SonarCloudPublish tasks. When I push changes to a new branch and my CI build runs the analysis shows up in the short lived branches in Sonar Cloud but the analysis appears empty. The analysis always shows 0 new lines of code. I would expect to be able to get a look at the coverage and issues in the branch prior to submitting a PR.

Hey there.

Do you see any code appearing in the Code tab of your short-lived branch?

No. The code tab is empty.

@Colin Any update on what could be causing this or some steps to help troubleshoot? This is rather strange as everything populates from the PR’s.

Hey @groogiam

Sorry for the delay.

A potential culprit (and a likely one) is the detection of changed lines. For this I would recommend checking the analysis logs for messages like this, and see if any warnings/errors are being produced.

14:21:08.074 INFO: SCM collecting changed files in the branch
14:21:08.240 INFO: SCM collecting changed files in the branch (done) | time=166ms
14:21:08.240 DEBUG: SCM information about changed files in the branch is not available

Even better if you can upload your analysis logs from a pull request and a short-lived branch here (sensitive information redacted), or I can open a PM.

@Colin I see the first two lines but not the third debug line. I’m not sure if that is because I don’t have debug logging enabled or it is just not there. If you open a PM I can send you the logs from my build agent. Thanks.

Hello @groogiam , sorry for the late response.
I see in your logs:

SCM reported changed lines for 0 files in the branch
Could you please tell me:

  1. Do you have any exclusion patterns? If yes, which ones?
  2. Did you changed any file for this analysed branch? The above log tell us that nothing has changed, but i think there is a misconfiguration somewhere.
  3. Do you have this issue in other branches? If yes, which ones?

Hi @Alexandre_Holzhey

  1. There are no exclusions in the sonar cloud configuration. Below is the task definitions from my build.yaml
  - task: SonarCloudPrepare@1
      SonarCloud: 'myorgSonarCloud'
      organization: 'myorg'
      scannerMode: 'MSBuild'
      projectKey: 'myproject'
      projectName: 'My Project'
      extraProperties: 'sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/**/coverage.opencover.xml'
  - task: SonarCloudAnalyze@1

  - task: SonarCloudPublish@1
      pollingTimeoutSec: '300'

There are some ignored folders in the .gitignore but none of them contain source code.

  1. Yes the branch I was testing width had a for loop added to one of the files.
        //added code to test sonar cloud results in ci.
        for (int i = 0; i < 10; i++)
  1. This happens in all other short lived branches. It does not happen for PR’s or the main branch.

Hi @groogiam:

  1. Good, looks like we don’t have an issue regarding the exclusions.
  2. Ok, i assume your project also have JS source, right? I mean: you added this line in a source file that is normally analysed in a PR and/or main branch.
  3. All clear. I looked on our side at different types of logs but i cannot see any issue. I can see that PRs are ok. The problem seems to be on the scanner/CI/CD side, maybe a configuration issue.

Let’s try to get a good sample to compare with the bad one you already provided (11_SonarCloudAnalyze.txt). Could you please change the same file as you did for item 2, adding the same changes:

//added code to test sonar cloud results in ci.
        for (int i = 0; i < 10; i++)

Then trigger an analysis by creating a PR instead of a short lived branch. Could you do this, please? I will create a private message for you to send me the scanner logs. Please proceed exactly like before.

Hello @groogiam. Following our conversation from a private message, i will reach out to other teams to understand better the information you provided. I will give you an update later this week.

Hello @groogiam . Could you please check how is the fetch depth configuration for your project and try so set it to 0 and run a new analysis? I don’t see this in your pipeline and it is in our tutorial:

You should add:

- checkout: self
  fetchDepth: 0

Then let me know if this fixes your issue, otherwise please share the scanner logs with me in the private message. Thanks!

This did not appear to fix the issue. I’ll post the scanner logs in the PM shortly. Thanks.

Hi @groogiam
The analysis shows a configuration problem for coverage as below:

"22022-12-01T02:41:08.6702855Z Attempting to locate the CodeCoverage.exe tool…
2022-12-01T02:41:08.6727752Z Attempting to locate the CodeCoverage.exe tool using setup configuration…
2022-12-01T02:41:08.6771699Z Visual Studio setup configuration was not found.
2022-12-01T02:41:08.6779711Z Attempting to locate the CodeCoverage.exe tool using registry…
2022-12-01T02:41:08.6806332Z WARNING: Failed to find the code coverage command line tool. Possible cause: Visual Studio is not installed, or the installed version does not support code coverage.
2022-12-01T02:41:08.6845047Z Process returned exit code 0

Do you still have the issue while analyzing?
I can see also that the used scanner version is not the latest, could you please try the latest version of the scanner?


Yes I still have the issue.

I don’t think the cited lines are the issue. I get the same message on PR builds and they display code analysis results including code coverage just fine. My build publishes code coverage results via coverlet in a previous step. The issue is that no analysis results are uploaded from non pr builds. E.g. Feature branch commits.

In regards to the scanner version. I am using the Azure Devops Extension which I don’t believe gives me any control of the scanner version. I have checked the extension definition in my dev ops instance and it says the latest version Installed version 1.39.0 (Latest) is installed.

We are coming on 6 months since I reported this issue and the lack of progress is becoming frustrating.

I am seeing the same issue with our scans. any update?

Any update here? We are coming up on a year with no resolution to this.

Hey @groogiam

@bogdana sent you a private message back in May for some additional details, and it looks like you never responded. Can you get back to her so the investigation can continue?

1 Like

Sorry I missed that private message. I have replied. Thanks.

1 Like

The issue was in branch names.
Deleting from SonarCloud UI the short-lived branch named main and renaming the long-lived master branch to the main solved it.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.