Sonar doesn't include in analyses code changes committed before first feature branch build is done

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)

  • what are you trying to achieve

  • what have you tried so far to achieve this

  • SonarQube: Developer EditionVersion 9.4 (build 54424)

  • Sonar Maven 3: Version 3.2.4•Bamboo Data Center 8.0.0 - 9.0.0

  • Sonar for Bitbucket: 6.0.3

  • Bamboo: 8.2.4 build 80210

  • Bitbucket: 8.2.2

  • JaCoCo: 0.8.8

Preconditions:
New Code is configured in sonarqube as Previous version

Steps to reproduce:

  1. Create new feature branch.
  2. Build is triggered.
  3. While first build is still lasting make code changes, commit and push, ideally three different commits.
  4. Affter innitial commit is finalised socond one is triggered automaticaly/manualy.
  5. All previously created commits are listed in Bamboo as part of second build.
  6. Build pass sonarqube quality check.
  7. All code changes added during execution of first build are NOT considered as New Code but as an old one and they are listed under Overall Code coverage.

Conclusion: New code will not be analyzed by sonar because it is not considered as new one.

Hey there.

You would want to use the “Reference Branch” New Code Period so that changes from before the first build are taken into account.

Hi Colin.

Yes, I did it with “Reference Branch”, however in that case in second build also New Code is not considered as new one but in build after that one, third sonar check.
So in that scenario I already have two green builds passed sonar quality check and that code can be merged as already analysed by sonar, but it is not.

Feel free to add the scanner logs of the various analyses that happened when you analyzed using Reference Branch, and screenshots that demonstrate the issue.

Hi Colin.

Here it is logs and Bamboo screenshots. I have cleaned some log data.

SONAR4BAMBOO_logs.txt (12.1 KB)


I’m more interesting in the logs from the scanner itself

INFO: Project root configuration file: NONE
INFO: SonarScanner 4.7.0.2747
INFO: Java 11.0.14.1 Eclipse Adoptium (64-bit)
INFO: Mac OS X 12.6 x86_64
.....

Hi Colin,

except logs I have added I can’t find any other sonar related logs in bamboo job logs. Can you advise me where else to look?

Thanks.