Jenkins : java.io.IOException: Cannot run program “node”: error=2, No such file or directory

大兔子大兔子 提交于 2020-06-27 16:21:24

问题


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


回答1:


You need to symlink the nodejs executable to node

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

Hope this helps!



来源:https://stackoverflow.com/questions/52778556/jenkins-java-io-ioexception-cannot-run-program-node-error-2-no-such-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!