Jenkins:java.io.IOException:无法运行程序“节点”:错误= 2,没有这样的文件或目录

Tro*_*jan 8 shell node.js jenkins

我是 jenkins 和 shell 脚本的新手,我有一个包含一些阶段的 Jenkins 管道脚本。正在安装 NOdejs。但我面临一些问题。我遇到以下错误。
**java.io.IOException:无法运行程序“node”:错误=2,没有这样的文件或目录**

请检查下面的代码并让我知道我犯的错误。

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"

   }
Run Code Online (Sandbox Code Playgroud)

日志消息:

  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)
Run Code Online (Sandbox Code Playgroud)

我正在使用Linux,感谢您的快速回复

Rin*_*haj 9

对于那些现在遇到这个问题的人,您可以从知道节点路径的命令行打开 android studio。在我的 mac 中,我使用 mac 终端打开 Android Studio,如下所示:

open -a /Applications/Android\ Studio.app
Run Code Online (Sandbox Code Playgroud)


Har*_*hal 7

您需要将nodejs可执行文件符号链接到node

sudo ln -s "$(which nodejs)" /usr/local/bin/node
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!

  • 啥啊啊啊啊啊? (3认同)