Code does not show up on short-lived branches

  • ALM used: Azure DevOps

  • CI system used: Azure DevOps

  • Scanner command used when applicable (private details masked):

    • task: SonarCloudPrepare@1
      inputs:
      SonarCloud: ‘SonarCloud’
      organization: ‘redacted’
      scannerMode: ‘CLI’
      configMode: ‘manual’
      cliProjectKey: ‘redacted’
      cliProjectName: ‘redacted’
      cliSources: ‘.\redactedCommon,redactedWeb’
      extraProperties: |
      sonar.java.binaries=.\redactedCommon\source\com\redacted\redacted*
      sonar.java.libraries=.\redactedCommon\lib*.jar
      sonar.c.file.suffixes=-
      sonar.cpp.file.suffixes=-
      sonar.objc.file.suffixes=-
  • Languages of the repository: Java

  • Error observed: No error. The scan actually runs successfully for the non-master (feature) branches. When I go to the Code tab to look at the code scanned it shows nothing. If I merge that same commit into master it the code shows up in the master branch scan.

Hey there.

Let me suggest you pass sonar.verbose=true and check the logs on such a pull request build (where no files are showing as changed). You are looking for logs starting around here:

07:27:39.608 INFO: SCM collecting changed files in the branch

Out of curiousity, what kind of files are these? Java files? another language? Source files? Test files?

There is a lot of stuff that has is “excluded by the scm ignore settings.” I dont have any scm ignore settings configured that I know of unless that means the .gitignore file? Other than that I don’t know what to look for.

It’s all Java. For the java.binaries I gave it the folder with all of the .class files for the libraries I gave it the area where the third party libraries are (.jar). The identified source folders contain .java files and some .jsp.

SonarQube will use the .gitignore file to automatically exclude some files from the analysis. You can try turning this off (-Dsonar.scm.exclusions.disabled=true) to see if it makes a difference.

However, do your logs indicate any files being marked as changed? Such as:

16:03:54.038 INFO: SCM collecting changed files in the branch (done) | time=1104ms
16:03:54.038 DEBUG: SCM reported 3783 files changed in the branch

Thank you I will try turning off the SCM. What is interesting is on my CI branches on the very first run it shows no files were changed. Shouldn’t the first run have all of the files identified within the sources? Other than that, just scanning new code makes sense for CI branches.