Sonar Scanner for Pull Request Failing with Jenkins MultiBranch and Bitbucket Server

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    - Sonarqube version: Data Center EditionVersion 7.9.4 (build 35981)
    - Sonar Scanner: sonar-scanner-4.4.0.2170-linux
  • what are you trying to achieve
    Scanning the Pull Request using Jenkins Multibranch with option “Discover Pull Request Revision” with “The Current Pull request Revision” . It seems that the code was picked up but the commit SHA is still not being identified hence sonar doesn’t even scan this branch.
  • what have you tried so far to achieve this
    I have tried the git fetch approach for the target branch per sonar documentation but no luck and I am still seeing the same issue. Below is the command that we run and below is the error I am seeing.

Sonar Scanner Command:

sonar-scanner -X -Dsonar.login=**** -Dsonar.branch.name=PR-353 -Dsonar.projectKey=xxxxxxxx -Dsonar.projectName=xxxxxxx -Dsonar.sources=src -Dsonar.java.binaries=target/classes -Dsonar.language=java -Dsonar.java.coveragePlugin=jacoco -Dsonar.junit.reportPaths=target/surefire-reports -Dsonar.surefire.reportsPath=target/surefire-reports

19:23:31  18:23:31.555 INFO: Branch name: PR-353, type: short living
19:23:31  18:23:31.565 INFO: SCM collecting changed files in the branch
19:23:32  18:23:31.647 INFO: ------------------------------------------------------------------------
19:23:32  18:23:31.647 INFO: EXECUTION FAILURE
19:23:32  18:23:31.647 INFO: ------------------------------------------------------------------------
19:23:32  18:23:31.647 INFO: Total time: 59.234s
19:23:32  18:23:31.692 INFO: Final Memory: 23M/84M
19:23:32  18:23:31.692 INFO: ------------------------------------------------------------------------
19:23:32  18:23:31.692 ERROR: Error during SonarScanner execution
19:23:32  java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.filesystem.ProjectFileIndexer
19:23:32  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)
19:23:32  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:678)
19:23:32  	at org.sonar.core.platform.ComponentContainer.getComponentByType(ComponentContainer.java:281)
19:23:32  	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:353)
19:23:32  	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
19:23:32  	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
19:23:32  	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
19:23:32  	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
19:23:32  	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
19:23:32  	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:73)
19:23:32  	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
19:23:32  	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
19:23:32  	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
19:23:32  	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
19:23:32  	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
19:23:32  	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
19:23:32  	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
19:23:32  	at com.sun.proxy.$Proxy0.execute(Unknown Source)
19:23:32  	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
19:23:32  	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
19:23:32  	at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
19:23:32  	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
19:23:32  	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
19:23:32  Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.filesystem.FileIndexer
19:23:32  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)
19:23:32  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
19:23:32  	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
19:23:32  	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
19:23:32  	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
19:23:32  	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
19:23:32  	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
19:23:32  	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
19:23:32  	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
19:23:32  	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
19:23:32  	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
19:23:32  	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
19:23:32  	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
19:23:32  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
19:23:32  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)
19:23:32  	... 22 more
19:23:32  Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.filesystem.MetadataGenerator
19:23:32  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)
19:23:32  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
19:23:32  	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
19:23:32  	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
19:23:32  	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
19:23:32  	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
19:23:32  	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
19:23:32  	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
19:23:32  	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
19:23:32  	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
19:23:32  	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
19:23:32  	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
19:23:32  	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
19:23:32  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
19:23:32  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)
19:23:32  	... 36 more
19:23:32  Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.filesystem.StatusDetection
19:23:32  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)
19:23:32  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
19:23:32  	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
19:23:32  	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
19:23:32  	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
19:23:32  	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
19:23:32  	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
19:23:32  	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
19:23:32  	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
19:23:32  	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
19:23:32  	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
19:23:32  	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
19:23:32  	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
19:23:32  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
19:23:32  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)
19:23:32  	... 50 more
19:23:32  Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scm.ScmChangedFiles
19:23:32  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)
19:23:32  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
19:23:32  	at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
19:23:32  	at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
19:23:32  	at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
19:23:32  	at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
19:23:32  	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
19:23:32  	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
19:23:32  	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
19:23:32  	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
19:23:32  	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
19:23:32  	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
19:23:32  	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
19:23:32  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
19:23:32  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)
19:23:32  	... 64 more
19:23:32  Caused by: java.lang.NullPointerException
19:23:32  	at org.eclipse.jgit.lib.ObjectIdOwnerMap.get(ObjectIdOwnerMap.java:138)
19:23:32  	at org.eclipse.jgit.revwalk.RevWalk.parseAny(RevWalk.java:888)
19:23:32  	at org.eclipse.jgit.revwalk.RevWalk.parseCommit(RevWalk.java:800)
19:23:32  	at org.sonarsource.scm.git.GitScmProviderBefore77.prepareTreeParser(GitScmProviderBefore77.java:196)
19:23:32  	at org.sonarsource.scm.git.GitScmProviderBefore77.branchChangedFiles(GitScmProviderBefore77.java:90)
19:23:32  	at org.sonar.scanner.scm.ScmChangedFilesProvider.loadChangedFilesIfNeeded(ScmChangedFilesProvider.java:63)
19:23:32  	at org.sonar.scanner.scm.ScmChangedFilesProvider.provide(ScmChangedFilesProvider.java:43)
19:23:32  	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
19:23:32  	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
19:23:32  	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
19:23:32  	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
19:23:32  	at org.picocontainer.injectors.MethodInjector.invokeMethod(MethodInjector.java:129)
19:23:32  	at org.picocontainer.injectors.MethodInjector.access$000(MethodInjector.java:39)
19:23:32  	at org.picocontainer.injectors.MethodInjector$2.run(MethodInjector.java:113)
19:23:32  	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
19:23:32  	at org.picocontainer.injectors.MethodInjector.decorateComponentInstance(MethodInjector.java:120)
19:23:32  	at org.picocontainer.injectors.CompositeInjector.decorateComponentInstance(CompositeInjector.java:58)
19:23:32  	at org.picocontainer.injectors.Reinjector.reinject(Reinjector.java:142)
19:23:32  	at org.picocontainer.injectors.ProviderAdapter.getComponentInstance(ProviderAdapter.java:96)
19:23:32  	at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
19:23:32  	at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
19:23:32  	at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)
19:23:32  	... 78 more

I would appreciate help, I have been really stuck and have tried all from the sonar documents.
Jenkins Multibranch doc with sonar + Bitbucket Server
Referred the below docs but no help

Bitbucket Server Integration | SonarQube Docs
Jenkins | SonarQube Docs

Hi,

Welcome to the community!

First, it’s incumbent upon me to point out that your version is past EOL. You should upgrade to either the latest version or the current LTS at your earliest convenience. At the moment SonarQube 8.9 happens to be both Latest and LTS. So you need to upgrade to 8.9. :smiley:

Regarding your question, what version of Java are you using to run the analysis?

 
Ann

thanks @ganncamp , the upgrade is planned soon.

Java version is 1.8.0_282 .

This is only happening in Pull Request from Bitbucket and jenkins . So by looking at the output I suspect the issue seems to be that the PR commit to the target branch diff is not being done by sonar so something weird on why sonar didn’t event see the PR branches on dashboard at all now.

Hi,

Thanks for your Java version. It looks fine to me.

This looks like an issue in the underlying JGit component. What version of the Git plugin are you running? It looks like the latest is 1.12. Here are the recent version summaries

1.12 Support for New Code based on a reference branch
1.11 Improve branch detection for PR analysis in Jenkins, support reference clone, update JGit

 
Ann

ok I will ask for the upgrade , but my question is this was working sometime back like 2 weeks ago and all of a sudden it stopped working.

Another thing is one of the PR where it is still working for me is a kind of merge from development branch to master branch and PR analysis between these 2 branches works just fine. I am wondering what got changed that it wont work for real Pull Requests and work for the ones for long lived branches as source vs target.

Hi,

I can only guess that something about your environment changed.

 
:woman_shrugging:
Ann

Well the only change that I made when this was working perfectly in multibranch configuration to have the branch scan too and filter the branch name with development and release. But I then reverted this and since then this is not working and it seems that target branch is not being checked somehow and it gives null pointer when sonar scanner tries to scan., Please see the output above.

what should be the right configuration for multi branch Jenkins plugin so sonar PR’s can be analyzed ? I think there is something weird . It did worked intermittently for the Bitbucket → Jenkins Multibranch —> Sonar scan for PRs . I think something with regards to the diff between PR branch and Target branch revision is not being picked , Please help how can scanner be made aware of this .