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.