7

I Am new to jenkins and shell script,I have a one Jenkins pipeline script with some stages.There am installing NOdejs.But am facing some problems. I am getting below error .
**java.io.IOException: Cannot run program "node": error=2, No such file or directory **

Please check the below code and let me know the mistake i did.

stage('Build') { // for display purposes

     sh "wget http://wwwin-xxxxxxxxxxx.xxxxxxxxxxxx.com/repo/softwares/node/node- 
        v8.11.1-linux-x64.zip"
        // sh "ls -l"
        sh "unzip node-v8.11.1-linux-x64.zip"
        sh "export PATH='${WORKSPACE}/node-v8.11.1-linux-x64/bin:$PATH'"

     sh "node-v8.11.1-linux-x64/bin/npm --version" 
}

   stage('Static Analysis'){
       def scannerHome = tool 'SONARQUBE_HOME';

       sh "rm -rf ${env.workspace}/xxxxx-core/node_modules"
       sh "rm -rf ${env.workspace}/xxxxx-core/microservices/core/node_modules"
       sh "rm -rf ${env.workspace}/xxxxx-core/microservices/auth/node_modules"
       sh "rm -rf ${env.workspace}/xxxxxx-core/microservices/xxxxx-ms/node_modules"
       sh "PATH=\"${WORKSPACE}/node-v8.11.3-linux-x64/bin:$PATH\" ${scannerHome}/bin/sonar-scanner -e -Dsonar.projectKey=xxxxxxxx.xxxx:xxxx-core -Dsonar.login=837687654756743509010101010-Dsonar.projectName=com.xxxxxxxxxx.services:xxxxxx-core  -Dsonar.sources=${env.workspace}/xxxxxx-core/src,${env.workspace}/xxxxxx-core/microservices/core/src,${env.workspace}/xxxxxxx-core/microservices/xxxx/src,${env.workspace}/x-xxxxxxxcore/microservices/osupgrade-ms -Dsonar.host.url=https://xxxxx-sonar-sjc.xxxxxxxx.com/sonar/ -Dsonar.analysis.mode=preview -Dsonar.issuesReport.html.enable=true"

   }

Log message:

  ERROR: Failed to get Node.js version. No CSS files will be analyzed.
 java.io.IOException: Cannot run program "node": error=2, No such file or 
 directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)

I am using Linux , thanks for the fast response

Trojan
  • 1,396
  • 2
  • 16
  • 19

3 Answers3

9

To those stumbling to this issue now, you can open the android studio from a command line that is aware of the node path. In my mac I used the mac terminal to open Android Studio like this:

open -a /Applications/Android\ Studio.app
Rinor Dreshaj
  • 1,032
  • 12
  • 24
  • the problem is about making `node` available on any new terminal session. whichever way you installed node, it just must be available from the get go of any new session. – joe Jun 13 '22 at 17:43
7

You need to symlink the nodejs executable to node

sudo ln -s "$(which nodejs)" /usr/local/bin/node

Hope this helps!

Harshal Yeole
  • 4,812
  • 1
  • 21
  • 43
  • I have added below code : sh "sudo ln -s /usr/bin/nodejs /usr/sbin/node" but got issue like : It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility. – Trojan Oct 12 '18 at 12:19
  • 3
    Whaaaaaaaaaaaat? – Harshal Yeole Oct 12 '18 at 12:29
  • Do i need to install node, even after unzip it. If yes, how to do that. – Trojan Oct 12 '18 at 12:45
  • I installed it from https://nodejs.org/en/download/ and this problem was fixed – pme Mar 22 '20 at 06:39
  • 1
    I had the same problem because I installed node with nvm. This command worked for me: 'sudo ln -s "$(which node)" /usr/local/bin/node' – nashvent Jun 11 '20 at 05:24
1

I am having the same problem.

I got this error in Mac when I had Node installed via nvm

Try Uninstall it , and install via NodeJS Site.

LINK - https://nodejs.org/en/

You will get rid of this error.

Ashish Kumar
  • 111
  • 1
  • 7