-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot call nvm exec
in bash script with set -e
#993
Comments
Using inline nonzero return codes is a common practice, and An alternative is to source |
For anyone using nvm in a CI environment, where non-zero exit codes are usually used to indicate a problem, I have this little snippet: export NODE_VERSION="5.9.0"
export NPM_VERSION="3.7.3"
export NVM_DIR="`pwd`/.nvm" # truly local nvm install not needing sudo
mkdir -p $NVM_DIR
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
nvm install $NODE_VERSION
nvm use --silent $NODE_VERSION
set -e # make the script fail if anything goes wrong from here
export npm_install=$NPM_VERSION
curl -L https://npmjs.org/install.sh | sh
npm install your-module
node `npm bin`/your-module |
@joscha is this still a problem if you move the While I do think that |
Yes, it doesnt't work, because most |
Hmm, 127 should only be the exit code when an incorrect command was entered, and the help output goes to stderr. Do you have a specific line where it exits? |
Unfortunately the build logs where I had problems with that (hence why I found this ticket) are gone, so I am not sure which of the commands failed exactly, but I remember that an order like this:
did not work. |
Executing this script works as expected with and without a default, with and without an
I'm going to close this for now. Please reopen if the issue occurs again and if anyone can be more specific about which command fails. |
I looked into this again and I think in some of our builds the $NODE_VERSION was empty and the command was this:
so I believe that it actually only fails when the version is omitted. The OP of this ticket also uses it without a version, so that would make sense. |
@joscha when the version is omitted and no |
Yes, it fails with exit code 3 |
Great - that's intentional then :-) |
I don't know if it could help someone but I just solve a similar problem using set -e and nvm into a bash script. The problem was a missing line break into the .nvmrc file. How to reproduce it :
#!/bin/bash
set -e
source ~/.nvm/nvm.sh
nvm --version
nvm use
|
@kncs hm, you're saying that if the |
My bad, of course I wouldn't ask you to fix it, my comment was only to help people that could have similar problems |
@kncs i'll try to reproduce (i want to fix it!) but your confirmation would help :-) |
Yes it seems that it breaks something. I join a zip containing a broken nvmrc and the bash script to help you reproduce it. |
@kncs thanks - i was able to find the line causing the error. Definitely every file ever should have a trailing newline, but, I'll figure out a way to make this not break. |
I'm having this problem using drone ci https://github.com/drone/dronehttps://github.com/drone/drone Drone automatically creates a script with |
@hedefalk if you can narrow down which commands are failing, and ideally using |
It appears #!/bin/sh
set -e
[ -z "${DEBUG}" ] || set -x
green="$(tput setaf 2)"
reset="$(tput sgr0)"
export NVM_DIR="$HOME/.nvm"
NODE_VERSION="7.8"
BASEDIR="$(dirname "$0")/.."
cd "$(dirname "$0")/.."
SHORT_PIPELINE_VERSION=${PIPELINE_VERSION#*/}
if [ ! -d $NVM_DIR ]; then
echo $green "\n==> Installing Node Version Manager" $reset
(
git clone -n https://github.com/creationix/nvm.git "$NVM_DIR"
cd "$NVM_DIR"
git checkout -q `git describe --abbrev=0 --tags --match "v[0-9]*" origin`
)
fi
. $NVM_DIR/nvm.sh
echo $green "\n==> Installing node" $reset
nvm install $NODE_VERSION The offending non-zero returning function is |
@andyearnshaw yes, please; a new issue would be great. |
I just wanna point out that this solved my problem with Bitbucket Pipeline using atlassian/ssh-run. I added this part on the script because only when it was running by the Pipeline it couldn't find node installation. Thanks ^^ |
If I call
nvm exec node foobar.js
in a bash script withset -e
everything exits early, this is not great for being able to use nvm in an automated build for example . . .The text was updated successfully, but these errors were encountered: