Ubuntu NVM不在Jenkins execute shell上工作
我正试图在Ubuntu服务器上安装并使用Jenkins execute shell脚本中的nvm,但出现以下错误: 16:00:21/tmp/hudson5983664925305072739.sh:第8行:nvm:命令不可用 发现 这是我迄今为止尝试过的,但没有成功:Ubuntu NVM不在Jenkins execute shell上工作,ubuntu,jenkins,continuous-integration,nvm,Ubuntu,Jenkins,Continuous Integration,Nvm,我正试图在Ubuntu服务器上安装并使用Jenkins execute shell脚本中的nvm,但出现以下错误: 16:00:21/tmp/hudson5983664925305072739.sh:第8行:nvm:命令不可用 发现 这是我迄今为止尝试过的,但没有成功: #!/bin/bash touch ~/.profile && source ~/.profile; nvm current || echo "SSH NVM is being installed" &
#!/bin/bash
touch ~/.profile && source ~/.profile;
nvm current || echo "SSH NVM is being installed" && touch ~/.profile && curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh && bash install_nvm.sh && source ~/.profile
echo "checking nvm"
bash ~/.nvm/nvm.sh;
nvm --version || exit 1;
Jenkins执行shell屏幕截图:
您需要记住,Jenkins正在非交互式shell中运行命令,因此路径与普通用户的路径不同。解决此问题的一种方法是使用绝对路径调用nvm。添加这些解决方案:
. ~/.nvm/nvm.sh
. ~/.profile
. ~/.bashrc
没有完全得到我在这里寻找的答案,但两者都让我找到了显而易见的解决方案,甚至在nvm的自述中。该路径不在Jenkins的shell脚本中,因此无法找到可执行文件
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
要了解您的$HOME
是什么,您可以运行echo$HOME
。
例如,$HOME
可能是这样的
export NVM_DIR="/var/lib/jenkins/.nvm"
在努力让上述建议发挥作用后,我尝试了NodeJS-Jenkins插件,它的效果非常好
您应该能够只使用
~/。nvm/nvm.sh
-其他两个配置可能比您需要的多得多,或者更少(在某些情况下,~/.bashrc
将在当前shell为非交互式时提前退出,即运行shell脚本)@RichVel是否有可能跨多个sh
调用使用此acc?Jenkins在单独的进程中运行每个sh
命令,因此您必须找到解决此问题的方法。如果您使用的是Ubuntu,您可以查看使用ENV
ENV变量来指向由dash
shell运行的脚本(默认/bin/sh
,请参见mansh
)-但是您需要确保Jenkins以某种方式作为登录shell运行/bin/sh
。也许在另一个答案中提到的NodeJS插件是一个更好的探索途径。