The Sonarqube is going for a full branch scan for PR builds

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube Server / Community Build, Scanner, Plugin, and any relevant extension) Sonarqube server
  • how is SonarQube deployed: zip, Docker, Helm : Helm
  • what are you trying to achieve: we are using Sonarqube for static code analysis for PR builds
  • what have you tried so far to achieve this: for PR builds, the Sonarqube used to scan only those changed files earlier. from last week, it is scanning entire branch

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!
logs:

[sonar:sonar] Process project properties
[sonar:sonar] Process project properties (done) | time=11ms
[sonar:sonar] Project key: sof.som.ci.master
[sonar:sonar] Base dir: /home/jenkins/agent/workspace/SOM-Sterling10-CL1CL2-PR_PR-3490/SOM-BuildDeploy/scripts/build/Wave_4.2.3
[sonar:sonar] Working dir: /home/jenkins/agent/workspace/SOM-Sterling10-CL1CL2-PR_PR-3490/SOM-BuildDeploy/scripts/build/Wave_4.2.3/.scannerwork
[sonar:sonar] Load project settings for component key: ‘sof.som.ci.master’
[sonar:sonar] Load project settings for component key: ‘sof.som.ci.master’ (done) | time=67ms
[sonar:sonar] Load project branches
[sonar:sonar] Load project branches (done) | time=49ms
[sonar:sonar] Load branch configuration
[sonar:sonar] Found manual configuration of branch/PR analysis. Skipping automatic configuration.
[sonar:sonar] Load branch configuration (done) | time=2ms
[sonar:sonar] Load quality profiles
[sonar:sonar] Load quality profiles (done) | time=116ms
[sonar:sonar] Auto-configuring with CI ‘Jenkins’
[sonar:sonar] Exclusions based on SCM info is disabled by configuration
[sonar:sonar] Load active rules
[sonar:sonar] Load active rules (done) | time=899ms
[sonar:sonar] Load analysis cache
[sonar:sonar] Load analysis cache (52.8 kB) | time=94ms
[sonar:sonar] Pull request 3490 for merge into master from 3490
[sonar:sonar] The property ‘sonar.login’ is deprecated and will be removed in the future. Please use the ‘sonar.token’ property instead when passing a token.
[sonar:sonar] Preprocessing files…
[sonar:sonar] 2 languages detected in 1307 preprocessed files
[sonar:sonar] 73 files ignored because of inclusion/exclusion patterns
[sonar:sonar] Loading plugins for detected languages
[sonar:sonar] Load/download plugins
[sonar:sonar] Load/download plugins (done) | time=12839ms
[sonar:sonar] SonarQube plugin API version is 11.1.0.2693, enabling the deprecated SpotBugs profile exporter
[sonar:sonar] Load project repositories
[sonar:sonar] Load project repositories (done) | time=181ms
[sonar:sonar] SCM collecting changed files in the branch
[sonar:sonar] Could not find ref ‘master’ in refs/heads, refs/remotes, refs/remotes/upstream or refs/remotes/origin
[sonar:sonar] SCM collecting changed files in the branch (done) | time=124ms
[sonar:sonar] Indexing files…
[sonar:sonar] Project configuration:
[sonar:sonar] Included sources: src/**
[sonar:sonar] Excluded sources: **/pojo/cancel/api/*.java, **/pojo/*.java, **/som/util/IKEAFileEncryptorDecryptor.java, test/**
[sonar:sonar] Included tests: test/**
[sonar:sonar] Excluded tests: src/**
[sonar:sonar] Excluded sources for coverage: ${sonar.coverage.exclusions}
[sonar:sonar] 1307 files indexed
[sonar:sonar] Using ECJ batch to parse 1 Main java source files with batch size 209 KB.
[sonar:sonar] Starting batch processing.
[sonar:sonar] 100% analyzed
[sonar:sonar] Batch processing: Done.
[sonar:sonar] Did not optimize analysis for any files, performed a full analysis for all 1 files.
[sonar:sonar] No “Test” source files to scan.
[sonar:sonar] No “Generated” source files to scan.
[sonar:sonar] Sensor JavaSensor [java] (done) | time=9291ms
[sonar:sonar] Sensor JaCoCo XML Report Importer [jacoco]
[sonar:sonar] Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
[sonar:sonar] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=2292ms
[sonar:sonar] Sensor Java Config Sensor [iac]
[sonar:sonar] 0 source files to be analyzed
[sonar:sonar] 0/0 source files have been analyzed
[sonar:sonar] Sensor Java Config Sensor [iac] (done) | time=110ms
[sonar:sonar] Sensor ThymeLeaf template sensor [securityjavafrontend]

[sonar:sonar]   * src/com/ikea/ibm/som/inventory/condition/IKEACheckCDCWareHouseZoneLevel.java
[sonar:sonar]   * src/com/ikea/ibm/som/util/IKEAJSONUtil.java
[sonar:sonar]   * test/com/ikea/ibm/som/notifications/api/IKEAHandleDeliveryReminderMsgTest.java
[sonar:sonar]   * test/com/ikea/ibm/som/order/api/IKEAConfirmCancelReleaseAPITest.java
[sonar:sonar]   * test/com/ikea/ibm/som/order/api/IKEAProcessMHSAllocationSuccessTest.java
[sonar:sonar] This may lead to missing/broken features in SonarQube
[sonar:sonar] CPD Executor 25 files had no CPD blocks
[sonar:sonar] CPD Executor Calculating CPD for 761 files
[sonar:sonar] CPD Executor CPD calculation finished (done) | time=902ms
[sonar:sonar] SCM revision ID 'cdf3e8cd2650133b1e1a6bb453f6d52fafb2052b'
[sonar:sonar] SCM writing changed lines
[sonar:sonar] Could not find ref 'master' in refs/heads, refs/remotes, refs/remotes/upstream or refs/remotes/origin
[sonar:sonar] SCM writing changed lines (done) | time=7ms
[sonar:sonar] Analysis report generated in 1557ms, dir size=15.4 MB
[sonar:sonar] Analysis report compressed in 4169ms, zip size=4.1 MB
[sonar:sonar] Analysis report generated in /home/jenkins/agent/workspace/SOM-Sterling10-CL1CL2-PR_PR-3490/SOM-BuildDeploy/scripts/build/Wave_4.2.3/.scannerwork/scanner-report
[sonar:sonar] Analysis report uploaded in 537ms

Hey @santhoshsathyamurthy and welcome to the community!

[sonar:sonar] Could not find ref ‘master’ in refs/heads, refs/remotes, refs/remotes/upstream or refs/remotes/origin

To analyze a PR, the scanner needs to run a git diff between the PR branch and its target branch (here, master) on the CI agent. Both the PR branch and the base branch must be fully fetched and present in .git on the agent (no shallow clone, base ref available). When that happens, the scanner falls back to analyzing as if it were a regular branch.

You need to make sure your CI is performing a full clone of the repo, and you need to ensure that the target branch of the PR exists in the git environment in which the analysis is running.