4
votes

While running sonar-scanner via Jenkins, we are getting the following error message. Jenkins and Sonarqube have been installed in Window Server 2008 OS. I have also tried installed node.js in the server but still, I am getting the same error message.

What are we missing? And why do we need this Node.js for analysis? We are basically analyzing HTML application. Though we get the below error message, the execution gets completed successfully. But we are trying to find the root cause for the below error.

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
Have you tried running node -v directly on your server (from command-line)? Is Node.js installation directory in your Path environment variable? - Wiktor Bednarz
@WiktorBednarz, yes doing node -v on command prompt works fine and also I have verified the Path environment variable where node.js installation path is given. - Vivek
Do I want to install, NodeJS Plugin on the Jenkins too? - Vivek
I had the same error message you had. For me, problem was resolved after adding node installation path to Path. At some point SonarQube wants to execute node -v, but it cannot find it. It seems it's executed as part of the ESLint plugin. As I don't use Jenkins myself, I'm not sure installing NodeJS Plugin will help, but it's certainly worth a try! - Wiktor Bednarz

3 Answers

1
votes

You have the CSS language plugin installed, which requires Node.js as a prerequisite, see plugin documentation.

Question comments indicate that you should put the Node.js installation directory on the PATH, but documentation suggests setting the sonar.nodejs.executable properly has the same effect.

0
votes

Upgrade the nodejs version to altest and try again.

0
votes

I think I might be onto something given that I am able to get it to work.

Basically, SonarQube worked with lcov reports without any problems (which is generated by most Karma reports by default - since it is configured by default in Angular/React). However, the memory problems started happening once I integrated karma-sonarqube-reporter plugin into Karma.

Few other answers on Stackoverflow indicated that the binary was corrupted - however, this was not the issue for me since a re-install did not do anything.

If you look at the sonarqube-scanner plugin - they say the binary is downloaded from this URL here. The thing to note here is that all the binaries are < version 6.2 - Which would mean karma-sonarqube-reporter would need to output the result in legacyMode. If you do that, the SonarQube is able to parse that file just fine, without any memory problems.

Attaching my configuration from karma.conf.js for the karma-sonarqube-reporter plugin:

    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';
      },

Note: legacyMode is set to true. Once I do this - I did not even need to give the max-memory property for sonar-scanner.