我想在Ubuntu服务器上使用Jenkins执行shell脚本安装和使用nvm,但是我遇到了以下错误:
16:00:21 /tmp/hudson5983664925305072739.sh: 第8行:nvm:找不到命令
我已经尝试了以下方法,但都没有成功:
#!/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脚本截图:
. ~/.nvm/nvm.sh
命令,而其他两个命令可能会配置比你需要的更多或更少(在某些情况下,如果当前shell是非交互式的,即运行shell脚本,则.bashrc
文件会提前退出)。 - RichVelsh
调用之间使用它? - velopsh
命令中都会运行一个单独的进程,因此您需要找到一种解决方法。如果您使用的是Ubuntu,可以考虑使用ENV
环境变量指向由dash
shell(默认为/bin/sh
,请参见man sh
)运行的脚本 - 但您需要确保Jenkins以某种方式运行/bin/sh
作为登录shell。也许另一个答案中提到的NodeJS插件是更好的探索路线。 - RichVel. ~/.bashrc
时,你会看到很多无用的日志。为了消除这些行,你应该在. ~/.bashrc
之前使用set +x
。 - Mohammad Ravanbakhsh