【问题标题】:Jenkins: -bash: command not found詹金斯:-bash:找不到命令
【发布时间】:2018-12-27 21:49:06
【问题描述】:

我正在尝试使用 Jenkins 构建我的 Node.js 应用程序,但出现此错误:

    -bash: npm: command not found
    -bash: pm2: command not found
    Build step 'Execute shell' marked build as failure
    Finished: FAILURE

我创建了一个部署文件并将其添加到我在 Jenkins 中的 Execute shell 中,它看起来像这样:

-#!/bin/sh
ssh ubuntu@development-server:ip <<EOF
    cd ~/nodeweb
    git pull
    npm install
    pm2 restart ecosystem.config.js
    exit
EOF

在我的开发服务器上,我已经安装了 npm 和 pm2 模块。

【问题讨论】:

标签: jenkins


【解决方案1】:

这是因为正常的 ssh 会话以非交互模式打开 shell 并且不获取 .bashrc 文件。

您的 npm 和 pm2 模块的 PATH 可以在 .bashrc 文件中配置,从而在您尝试通过非交互式 shell 执行 npm install 时抛出未找到错误。

要让 ssh 使用交互模式,只需在 ssh 命令中使用 -i 标志。

#!/bin/sh
ssh ubuntu@development-server:ip 'bash -i' <<EOF
    cd ~/nodeweb
    git pull
    npm install
    pm2 restart ecosystem.config.js
    exit
EOF

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-30
    • 2014-07-24
    • 2018-02-05
    相关资源
    最近更新 更多