詹金斯声纳集成不工作

Jenkins to Sonar Integration Not Working

我使用的是 Jenkins 版本 2.7.1,我目前在与 Sonar 通信时遇到问题。 我们的企业 Sonar 当前版本为 4.5.4,我们不允许更改此版本 在詹金斯我使用 Maven 3.3.9

我得到的错误如下

       05:49:46 [INFO] SonarQube version: 4.5.4
05:49:48 [INFO] Default locale: "en_US", source code encoding: "UTF-8"
05:49:49 [INFO] [05:49:49.050] Load global referentials...
05:49:49 [INFO] [05:49:49.185] Load global referentials done: 138 ms
05:49:49 [INFO] ------------------------------------------------------------------------
05:49:49 [INFO] BUILD FAILURE
05:49:49 [INFO] ------------------------------------------------------------------------
05:49:49 [INFO] Total time: 6.069 s
05:49:49 [INFO] Finished at: 2016-07-20T05:49:49-04:00
05:49:49 [INFO] Final Memory: 23M/237M
05:49:49 [INFO] ------------------------------------------------------------------------
05:49:49 [ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2:sonar (default-cli) on project services-web: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 -> [Help 1]
05:49:49 org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2:sonar (default-cli) on project services-web: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1
05:49:49    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
05:49:49    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
05:49:49    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
05:49:49    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
05:49:49    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
05:49:49    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
05:49:49    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
05:49:49    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
05:49:49    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
05:49:49    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
05:49:49    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
05:49:49    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
05:49:49    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
05:49:49    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
05:49:49    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
05:49:49    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
05:49:49    at java.lang.reflect.Method.invoke(Method.java:497)
05:49:49    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
05:49:49    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
05:49:49    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
05:49:49    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
05:49:49 Caused by: org.apache.maven.plugin.MojoExecutionException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1
05:49:49    at org.sonarsource.scanner.maven.bootstrap.ExceptionHandling.handle(ExceptionHandling.java:36)
05:49:49    at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.execute(ScannerBootstrapper.java:81)
05:49:49    at org.sonarsource.scanner.maven.SonarQubeMojo.execute(SonarQubeMojo.java:112)
05:49:49    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
05:49:49    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
05:49:49    ... 20 more
05:49:49 Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1
05:49:49    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:176)
05:49:49    at com.google.gson.Gson.fromJson(Gson.java:803)
05:49:49    at com.google.gson.Gson.fromJson(Gson.java:768)
05:49:49    at com.google.gson.Gson.fromJson(Gson.java:717)
05:49:49    at com.google.gson.Gson.fromJson(Gson.java:689)
05:49:49    at org.sonar.batch.protocol.input.GlobalReferentials.fromJson(GlobalReferentials.java:70)
05:49:49    at org.sonar.batch.referential.DefaultGlobalReferentialsLoader.load(DefaultGlobalReferentialsLoader.java:37)
05:49:49    at org.sonar.batch.referential.GlobalReferentialsProvider.provide(GlobalReferentialsProvider.java:38)
05:49:49    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
05:49:49    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
05:49:49    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
05:49:49    at java.lang.reflect.Method.invoke(Method.java:497)
05:49:49    at org.picocontainer.injectors.MethodInjector.invokeMethod(MethodInjector.java:129)
05:49:49    at org.picocontainer.injectors.MethodInjector.access[=10=]0(MethodInjector.java:39)
05:49:49    at org.picocontainer.injectors.MethodInjector.run(MethodInjector.java:113)
05:49:49    at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
05:49:49    at org.picocontainer.injectors.MethodInjector.decorateComponentInstance(MethodInjector.java:120)
05:49:49    at org.picocontainer.injectors.CompositeInjector.decorateComponentInstance(CompositeInjector.java:58)
05:49:49    at org.picocontainer.injectors.Reinjector.reinject(Reinjector.java:142)
05:49:49    at org.picocontainer.injectors.ProviderAdapter.getComponentInstance(ProviderAdapter.java:96)
05:49:49    at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:698)
05:49:49    at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:646)
05:49:49    at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:631)
05:49:49    at org.picocontainer.parameters.BasicComponentParameter.resolveInstance(BasicComponentParameter.java:118)
05:49:49    at org.picocontainer.parameters.ComponentParameter.resolveInstance(ComponentParameter.java:136)
05:49:49    at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
05:49:49    at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
05:49:49    at org.picocontainer.injectors.ConstructorInjector.run(ConstructorInjector.java:335)
05:49:49    at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
05:49:49    at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
05:49:49    at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
05:49:49    at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
05:49:49    at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
05:49:49    at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:698)
05:49:49    at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:646)
05:49:49    at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:631)
05:49:49    at org.picocontainer.parameters.BasicComponentParameter.resolveInstance(BasicComponentParameter.java:118)
05:49:49    at org.picocontainer.parameters.ComponentParameter.resolveInstance(ComponentParameter.java:136)
05:49:49    at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
05:49:49    at org.picocontainer.injectors.SingleMemberInjector.getMemberArguments(SingleMemberInjector.java:61)
05:49:49    at org.picocontainer.injectors.MethodInjector.getMemberArguments(MethodInjector.java:100)
05:49:49    at org.picocontainer.injectors.MethodInjector.run(MethodInjector.java:112)
05:49:49    at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
05:49:49    at org.picocontainer.injectors.MethodInjector.decorateComponentInstance(MethodInjector.java:120)
05:49:49    at org.picocontainer.injectors.CompositeInjector.decorateComponentInstance(CompositeInjector.java:58)
05:49:49    at org.picocontainer.injectors.Reinjector.reinject(Reinjector.java:142)
05:49:49    at org.picocontainer.injectors.ProviderAdapter.getComponentInstance(ProviderAdapter.java:96)
05:49:49    at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:698)
05:49:49    at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:646)
05:49:49    at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:631)
05:49:49    at org.picocontainer.parameters.BasicComponentParameter.resolveInstance(BasicComponentParameter.java:118)
05:49:49    at org.picocontainer.parameters.ComponentParameter.resolveInstance(ComponentParameter.java:136)
05:49:49    at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
05:49:49    at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
05:49:49    at org.picocontainer.injectors.ConstructorInjector.run(ConstructorInjector.java:335)
05:49:49    at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
05:49:49    at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
05:49:49    at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
05:49:49    at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
05:49:49    at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
05:49:49    at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:698)
05:49:49    at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:646)
05:49:49    at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:631)
05:49:49    at org.picocontainer.parameters.BasicComponentParameter.resolveInstance(BasicComponentParameter.java:118)
05:49:49    at org.picocontainer.parameters.ComponentParameter.resolveInstance(ComponentParameter.java:136)
05:49:49    at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
05:49:49    at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
05:49:49    at org.picocontainer.injectors.ConstructorInjector.run(ConstructorInjector.java:335)
05:49:49    at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
05:49:49    at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
05:49:49    at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
05:49:49    at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
05:49:49    at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
05:49:49    at org.picocontainer.DefaultPicoContainer.instantiateComponentAsIsStartable(DefaultPicoContainer.java:1033)
05:49:49    at org.picocontainer.DefaultPicoContainer.addAdapterIfStartable(DefaultPicoContainer.java:1025)
05:49:49    at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1002)
05:49:49    at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:766)
05:49:49    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
05:49:49    at org.sonar.batch.bootstrapper.Batch.start(Batch.java:81)
05:49:49    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
05:49:49    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.executeOldVersion(BatchIsolatedLauncher.java:70)
05:49:49    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
05:49:49    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
05:49:49    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
05:49:49    at java.lang.reflect.Method.invoke(Method.java:497)
05:49:49    at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
05:49:49    at com.sun.proxy.$Proxy23.executeOldVersion(Unknown Source)
05:49:49    at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:245)
05:49:49    at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
05:49:49    at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.execute(ScannerBootstrapper.java:78)
05:49:49    ... 23 more
05:49:49 Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1
05:49:49    at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:374)
05:49:49    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:165)
05:49:49    ... 112 more

问题:有人知道我需要更改什么才能使它正常工作吗?

仅供参考 - 我在没有 jenkins 的情况下在本地尝试过这个 - 只是 运行 maven 命令并得到了同样的错误。

由于正确追踪此问题所需的详细程度超出了您通过问题描述实际提供的范围,因此以下是一些可能的故障排除途径:

  • 降级 Sonar Maven 插件:尽管 official documentation 指出:

    From maven-sonar-plugin 2.7, SonarQube < 4.5 is no longer supported. If using SonarQube instance prior to 4.5, you should use maven-sonar-plugin 2.6.

    因此,版本 4.5.4 确实应该受到您当前使用的插件 (org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2) 的支持,这可能是一种兼容性边缘情况,因此值得尝试早期版本。但是请注意,早期的主要版本为其 groupId 协调了不同的 Maven(GAV、GroupId、ArtifactId、Version):org.codehaus.mojo:sonar-maven-plugin:jar:2.7.1

  • 检查代理设置:一个非常相似的错误(几乎相同的堆栈跟踪)已经reported并且(未经证实的)结论是:

    the error ... means that the response is probably corrupted by your proxy.

    Please compare original response (without using your proxy) and the one you get from the proxy.