Sonarqube在运行声纳扫描仪时给出了node.js错误

时间:2019-04-18 21:03:17

标签: sonarqube sonarscanner

通过Jenkins运行声纳扫描仪时,我们收到以下错误消息。 Jenkins和Sonarqube已安装在Window Server 2008 OS中。我也尝试在服务器中安装node.js,但仍然收到相同的错误消息。

我们缺少什么?为什么我们需要这个Node.js进行分析?我们基本上是在分析HTML应用程序。尽管我们收到以下错误消息,但执行成功完成。但是,我们正在尝试寻找以下错误的根本原因。

ERROR: Error when running: 'node -v'. Is Node.js available during analysis?
org.sonarsource.nodejs.NodeCommandException: Error when running: 'node -v'. Is Node.js available during analysis?
    at org.sonarsource.nodejs.NodeCommand.start(NodeCommand.java:77)
    at org.sonarsource.nodejs.NodeCommandBuilderImpl.getVersion(NodeCommandBuilderImpl.java:171)
    at org.sonarsource.nodejs.NodeCommandBuilderImpl.checkNodeCompatibility(NodeCommandBuilderImpl.java:144)
    at org.sonarsource.nodejs.NodeCommandBuilderImpl.build(NodeCommandBuilderImpl.java:120)
    at org.sonar.plugins.javascript.eslint.EslintBridgeServerImpl.initNodeCommand(EslintBridgeServerImpl.java:129)
    at org.sonar.plugins.javascript.eslint.EslintBridgeServerImpl.startServer(EslintBridgeServerImpl.java:105)
    at org.sonar.plugins.javascript.eslint.EslintBridgeServerImpl.startServerLazily(EslintBridgeServerImpl.java:145)
    at org.sonar.plugins.javascript.eslint.EslintBasedRulesSensor.execute(EslintBasedRulesSensor.java:92)
    at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
    at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:359)
    at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:354)
    at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:317)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:128)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:73)
    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    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:185)
    at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:137)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:111)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
    at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.io.IOException: Cannot run program "node": CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(Unknown Source)
    at org.sonarsource.nodejs.NodeCommand$ProcessWrapperImpl.start(NodeCommand.java:154)
    at org.sonarsource.nodejs.NodeCommand.start(NodeCommand.java:73)
    ... 37 common frames omitted
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    ... 40 common frames omitted

3 个答案:

答案 0 :(得分:0)

您已安装CSS语言插件,该插件要求先安装Node.js,请参见plugin documentation

问题注释表明您应该将Node.js安装目录放在PATH上,但是文档建议正确设置sonar.nodejs.executable具有相同的效果。

答案 1 :(得分:0)

将nodejs版本升级到altest,然后重试。

答案 2 :(得分:0)

鉴于我能够让它发挥作用,我想我可能会做一些事情。

基本上,SonarQube 使用 lcov 报告没有任何问题(默认情况下由大多数 Karma 报告生成 - 因为它在 Angular/React 中默认配置)。但是,一旦我将 karma-sonarqube-reporter 插件集成到 Karma 中,内存问题就开始发生。

Stackoverflow 上的其他几个答案表明二进制文件已损坏 - 然而,这对我来说不是问题,因为重新安装没有做任何事情。

如果您查看 sonarqube-scanner 插件 - 他们说二进制文件是从此 URL here 下载的。这里要注意的是,所有二进制文件都低于 6.2 版 - 这意味着 karma-sonarqube-reporter 需要在 legacyMode 中输出结果。如果您这样做,SonarQube 能够很好地解析该文件,而不会出现任何内存问题。

karma.conf.jskarma-sonarqube-reporter 插件附加我的配置:

    sonarqubeReporter: {
      basePath: 'src/app',        // test files folder
      filePattern: '**/*spec.ts', // test files glob pattern
      encoding: 'utf-8',          // test files encoding
      outputFolder: 'reports',    // report destination
      legacyMode: true,          // report for Sonarqube < 6.2 (disabled)
      reportName: function(metadata) { // report name callback, but accepts also a
        // string (file name) to generate a single file
        /**
         * Report metadata array:
         * - metadata[0] = browser name
         * - metadata[1] = browser version
         * - metadata[2] = plataform name
         * - metadata[3] = plataform version
         */
        return 'sonarqube_report.xml';
      },

注意:legacyMode 设置为 true。一旦我这样做了 - 我什至不需要为声纳扫描仪提供 max-memory 属性。