gpt4 book ai didi

node.js - 在 Jenkins 中执行 SSH 命令时,bash 配置文件与使用同一用户通过 SSH 连接时不同

转载 作者:行者123 更新时间:2023-12-04 18:58:07 25 4
gpt4 key购买 nike

我正在尝试使用 Jenkins SSH exec 功能在远程服务器上运行一些 CLI nodejs 命令。

我在尝试永久运行时收到一条错误消息,我已使用 npm 全局安装了该消息。

编辑:错误是; -bash: forever: command not found .

以 root 身份通过 SSH 连接并运行 which npm返回;

/root/local/bin/npm

而通过 Jenkins,使用与 root 返回相同的命令;
/usr/bin/npm

我尝试过设置 bash 变量,但这些变量似乎在两种连接介质中也不一致。

两者都是使用此处详述的顶级方法安装的; https://gist.github.com/isaacs/579814#file-node-and-npm-in-30-seconds-sh

最佳答案

尝试这个:

ssh user@host -t 'bash -l -c "forever"'

您可以阅读 man ssh :

If command is specified, it is executed on the remote host instead of a login shell.



没有 login shell没有 rc-files ( .bashrc.bash_profile 等)所以可能没有 $PATH你期望有。

要了解有关登录 shell 的更多信息,请查看 man bash并搜索 -l选项说明。

关于node.js - 在 Jenkins 中执行 SSH 命令时,bash 配置文件与使用同一用户通过 SSH 连接时不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23501092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com