Short-lived branch analysis seems to be empty


(Ashley Ward) #1

I’m using the gradle sonarqube plugin (2.6.2) to analyse a Java project, using CircleCI.

It’s analysing the master branch fine, but when I use ‘-Dsonar.branch.name’ to analyse a feature branch the analysis runs through and the branch is created within sonarcloud, but the code is empty and there are no issues listed.

Am I doing something wrong here?

  - run:
      name: SonarQube analysis
      command: |
        gradle sonarqube \
            -Dsonar.login=$SONAR_LOGIN\
            -Dsonar.branch.name=$CIRCLE_BRANCH

Note that the other sonar properties (organisation, project, etc) are set from within the gradle build, and it’s creating the branch in sonar in the correct project so the connection to sonar seems to be working.


Lines to cover on new code is 0 in PR and for branches
PR analysis shows no code on one specific long-lived branch
(G Ann Campbell) #2

Hi,

Just to be sure, can you send a screenshot of a branch’s Code page?

 
Ann


(Ashley Ward) #3

Hi Ann

Here’s what the code screen looks like - empty!

Any ideas?

Thanks,

Ash


(G Ann Campbell) #4

Hi Ash,

Yep. That’s empty. :slight_smile:

Honestly, I was hoping you were speaking metaphorically. Clearly not.

So now for some details:

  • What version are you on?
  • This is specifically a SLB analysis and not a PR?
  • Did you by chance delete more lines than you added or modified?

 
Ann


(Ashley Ward) #5

Hi Ann,

I’m using SonarCloud. I’m using version 2.6.2 of the gradle plugin.

Yeah, it’s a SLB analysis using sonar.branch.name. It’s creating the branch in the UI so something’s working, there’s just no code!

This was on a test commit where I only added a couple of lines where I would expect an issue to be raised (an unchecked nullable access).

I’ve also checked all the branches (there are quite a few) that the team have created and they’re all blank too.

Thanks,

Ash


(G Ann Campbell) #6

Hi Ash,

Doh! Sorry I missed that.

Did you explicitly specify the target branch, or let it default to master? And if the latter, could you try making explicit?

 
Ann


(Ashley Ward) #7

I hadn’t explicitly set the target branch, so tried explicitly setting it to master and it’s still the same (no code or issues shown)

gradle sonarqube \
    -Dsonar.login=$SONAR_LOGIN \
    -Dsonar.branch.name=$CIRCLE_BRANCH \
    -Dsonar.branch.target=master \
    --debug

I’m running gradle in debug mode and it looks like it’s successfully creating a report (size = ~1MB) and uploading it with a 200. It’s just not showing anything in the UI.

18:40:36.174 [INFO] [org.sonarqube.gradle.SonarQubeTask] Analysis report generated in 392ms, dir size=1 MB
18:40:36.782 [INFO] [org.sonarqube.gradle.SonarQubeTask] Analysis reports compressed in 607ms, zip size=947 KB
18:40:36.782 [INFO] [org.sonarqube.gradle.SonarQubeTask] Analysis report generated in /home/circleci/app/build/sonar/scanner-report
18:40:36.782 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Upload report
18:40:38.211 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] POST 200 https://sonarcloud.io/api/ce/submit?organization=xxxxxxxxxxx&projectKey=xxxxxxxxxxx&projectName=xxxxxxxxxxx&characteristic=branch%3Dsonar&characteristic=branchType%3DSHORT | time=1428ms
18:40:38.213 [INFO] [org.sonarqube.gradle.SonarQubeTask] Analysis report uploaded in 1430ms
18:40:38.215 [INFO] [org.sonarqube.gradle.SonarQubeTask] ANALYSIS SUCCESSFUL, you can browse https://sonarcloud.io/dashboard?id=xxxxxxxxxxx&branch=sonar&resolved=false

(Ashley Ward) #9

Any ideas on this?

I’ve set up a new project and it’s doing the same thing - the master is analysed fine, but the SLBs are all empty. Interestingly I noticed that the coverage estimation is different on each of the SLBs, so there is something happening somewhere!


(Matthew West) #10

Did you come to a resolution on this? I am experiencing the exact same issue but using AppVeyor for CI.


(Alex Pabouctsidis) #12

We’re having the exact same issue. We are triggering the builds + analysis in bitbucket pipelines.

Here is our pipelines yml file bitbucket-pipelines.yml.txt (2.7 KB)

Our core long term branch is develop. When ever the develop build is triggered, the sonarcloud is updated correctly.

However, if I trigger a custom build “Sonarcloud” from a branch, the branch appears in sonarcloud, but its empty. exactly like the others:


(Simon Brandhof) #13

This is the expected behaviour if your branch is considered as “short-lived”. Only the new and modified files, compared to the “target branch”, are displayed and can contain issues.
By default branches are short-lived if their name does not start with “branch” nor “release”.
Is it your case?
See https://sonarcloud.io/documentation/branches/overview/ for more details.


(Oskar Karlsson) #14

Having the same issue with my builds from AWS Codebuild running sonarscanner for msbuild: https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/4.4.2.1543/sonar-scanner-msbuild-4.4.2.1543-netcoreapp2.0.zip

I get the correct results in my long term branch, but in my short term branch it only displays some of the projects and with faulty information:


(Alex Pabouctsidis) #15

In our case it doesn’t show any modified files or new lines, hence the issue.

Just to clarify what we do in our pipelines build script when we trigger a sonarcloud branch analysis.

  1. checkout develop branch (our long-term target branch)
  2. merge feature branch into develop branch.
  3. build and scan merged code with “sonar-scanner -Dsonar.branch.name=$BITBUCKET_BRANCH” where $BITBUCKET_BRANCH is the name of the short lives feature branch.

Could the issue be that we are analysis the post merged code?


(Duarte Meneses) #16

Hi Ashley,

Please have a look at this topic:

There is a bug in the code checkout done by circleci.
Could you try the work arounds described there?