Closed fjalars closed 6 years ago
I found a solution to this particular issue after researching the source code.
When we run our SonarQube job in Jenkins we have been running the git clone step in a command window where the working dir is /var/jenkins_home/workspace so the repo is created there.
With the repo there, the plugin complained with the error: "Failed to execute project builder: ch.mibex.bitbucket.sonar.review.PullRequestProjectBuilder"
From the information I gathered about the class GitBaseDirResolver in the source code, I found out that the plugin did not manage to find any .git repo in Jenkin's base working directory (/var/jenkins_home/workspace) although it was there, possibly because it looked for .git file in that particular directory and if it didn't find it, went to the parent and looked there, instead of looking deeper because the git project's name is known. I am not sure about this. I am not a Scala programmer and didn't have time to study the code completely.
What I did - as a trial - was to add a folder called ".git" in /var/jenkins_home/workspace and clone the git repo inside this .git folder, so it looked like this:
/var/jenkins_home/workspace/.git/
instead of
/var/jenkins_home/workspace/
and that did the trick.
Expected Behavior
I am trying out your plug-in and am expecting it to push results from sonar-scanner to my bitbucket account.
Actual Behavior
This is the config I run with sonar-scanner in Jenkins:
-# must be unique in a given SonarQube instance sonar.projectKey=joesproject -# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1. sonar.projectName=joesproject sonar.projectVersion=1.0
-# Path is relative to the sonar-project.properties file. Replace “\” by “/” on Windows. -# This property is optional if sonar.modules is set. sonar.sources=.
-# Encoding of the source code. Default is default system encoding sonar.sourceEncoding=UTF-8 sonar.verbose=true
-# Interacting with bitbucket sonar.bitbucket.repoSlug=$REPO_SLUG sonar.bitbucket.accountName= sonar.bitbucket.teamName= sonar.bitbucket.apiKey= sonar.bitbucket.branchName=$BRANCH_NAME sonar.host.url=http://sonarqube:9000 sonar.login= sonar.password=*** sonar.analysis.mode=issues
and it runs while the sonar-bitbucket plugin is not installed (copied to /extensions/plugins/. and server restarted). But when I add the plug-in to SonarQube, this is the error message I get in Jenkins . From this output I guess the problem lies in here:
Caused by: Failed to execute project builder: ch.mibex.bitbucket.sonar.review.PullRequestProjectBuilder Caused by: java.lang.IllegalArgumentException: [sonar4bitbucket] Unable to locate Git directory in /var/jenkins_home/workspace/sonarqube-test-2
Here is the full log from where the error start:
12:27:33.398 ERROR: Error during SonarQube Scanner execution java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.ProjectLock at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:64) at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:678) at org.sonar.core.platform.ComponentContainer.getComponentByType(ComponentContainer.java:265) at org.sonar.scanner.scan.ProjectScanContainer.doBeforeStart(ProjectScanContainer.java:118) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:133) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121) at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48) at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:84) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121) at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:121) at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116) at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:111) at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60) at com.sun.proxy.$Proxy0.execute(Unknown Source) at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233) at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151) at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123) at org.sonarsource.scanner.cli.Main.execute(Main.java:77) at org.sonarsource.scanner.cli.Main.main(Main.java:61) Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.DefaultInputModuleHierarchy at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:64) at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632) at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118) at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136) at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78) at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309) at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335) at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270) at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364) at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56) at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64) at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91) at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699) at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647) at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:62) ... 24 more Caused by: Failed to execute project builder: ch.mibex.bitbucket.sonar.review.PullRequestProjectBuilder Caused by: java.lang.IllegalArgumentException: [sonar4bitbucket] Unable to locate Git directory in /var/jenkins_home/workspace/sonarqube-test-2 at ch.mibex.bitbucket.sonar.GitBaseDirResolver$$anonfun$init$1.apply(GitBaseDirResolver.scala:22) at ch.mibex.bitbucket.sonar.GitBaseDirResolver$$anonfun$init$1.apply(GitBaseDirResolver.scala:22) at scala.Option.getOrElse(Option.scala:121) at ch.mibex.bitbucket.sonar.GitBaseDirResolver.init(GitBaseDirResolver.scala:21) at ch.mibex.bitbucket.sonar.review.PullRequestProjectBuilder.initGitBaseDir(PullRequestProjectBuilder.scala:22) at ch.mibex.bitbucket.sonar.review.PullRequestProjectBuilder.build(PullRequestProjectBuilder.scala:17) at org.sonar.scanner.scan.ProjectBuildersExecutor.execute(ProjectBuildersExecutor.java:52) at org.sonar.scanner.scan.InputModuleHierarchyProvider.provide(InputModuleHierarchyProvider.java:39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.picocontainer.injectors.MethodInjector.invokeMethod(MethodInjector.java:129) at org.picocontainer.injectors.MethodInjector.access$000(MethodInjector.java:39) at org.picocontainer.injectors.MethodInjector$2.run(MethodInjector.java:113) at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270) at org.picocontainer.injectors.MethodInjector.decorateComponentInstance(MethodInjector.java:120) at org.picocontainer.injectors.CompositeInjector.decorateComponentInstance(CompositeInjector.java:58) at org.picocontainer.injectors.Reinjector.reinject(Reinjector.java:142) at org.picocontainer.injectors.ProviderAdapter.getComponentInstance(ProviderAdapter.java:96) at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699) at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647) at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:62) at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632) at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118) at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136) at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78) at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309) at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335) at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270) at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364) at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56) at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64) at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91) at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699) at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647) at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:62) at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:678) at org.sonar.core.platform.ComponentContainer.getComponentByType(ComponentContainer.java:265) at org.sonar.scanner.scan.ProjectScanContainer.doBeforeStart(ProjectScanContainer.java:118) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:133) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121) at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48) at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:84) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121) at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:121) at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116) at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:111) at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60) at com.sun.proxy.$Proxy0.execute(Unknown Source) at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233) at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151) at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123) at org.sonarsource.scanner.cli.Main.execute(Main.java:77) at org.sonarsource.scanner.cli.Main.main(Main.java:61) 12:27:33.400 ERROR: 12:27:33.400 ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging. 12:27:33.401 DEBUG: Execution getVersion 12:27:33.401 DEBUG: Execution stop ERROR: SonarQube scanner exited with non-zero code: 1 Finished: FAILURE
Plug-in version, SonarQube version, CI system, build type
SonarQube version: 6.7.1.35068 Jenkins version: 2.89.2 Bitbucket.org