In the first stage of a Bluemix pipeline, by following approximately instructions from SO 42269590 and from the article I am able to get NVM installed and update to the latest version of nodejs with:
#!/bin/bash
echo " "
echo "= = = = = = = = = = = "
echo "PATH $PATH" | tr ':' '\n'
echo " "
echo "= = = = = = = = = = = "
echo "loading nvm ..."
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
# make nvm available immediately
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
echo " "
echo "= = = = = = = = = = = "
echo "Is nvm installed?"
command -v nvm
nvm --version
# based on this recommendation in the error logs
# nvm is not compatible with the npm config "prefix" option: currently set to "/home/pipeline/.npm-global"
# Run `npm config delete prefix` or `nvm use --delete-prefix v11.2.0` to unset it.
echo " "
echo "= = = = = = = = = = = "
echo "config delete prefix..."
npm config delete prefix
echo " "
echo "= = = = = = = = = = = "
echo "Installing the latest version of nodejs"
nvm install node
# remember to add below directory name to
# Build Archive Directory field of this configuration
mkdir build_archive_dir
echo " "
echo "= = = = = = = = = = = "
echo "Which node version is it?"
node -v
echo " "
echo "= = = = = = = = = = = = = = = = = = ="
echo "prepare to load nvm in the next stage"
# do not do this with every build. It only needs to be added once.
#echo 'export NVM_DIR="$HOME/.nvm" ' >> /home/pipeline/.bashrc
#echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm ' >> /home/pipeline/.bashrc
#echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion ' >> /home/pipeline/.bashrc
echo " "
echo "= = = = = = = = = = = = = = = = = = ="
echo "contents of /home/pipeline/.bashrc:"
cat /home/pipeline/.bashrc
echo " "
echo "= = = = = = = = = = = = = = = = = = ="
currentDirectory=`pwd`
echo "Contents of directory "$currentDirectory
ls -al
echo " "
However, in the next pipeline stage I am expecting to be able to use my recently loaded node version. The problem is that nodejs latest is not enabled and reverted back to the original default nodejs version. Not only that but it appears the pipeline is editing the .bashrc file and removing lines added in the previous stage and removing the .nvm folder. Hmmm mmm, totally bizarre. There is not much sense in running a bash script in a stage, if the pipeline is going to undo all the work of the previous stage.
The next stage Input is set to Input Type : Build artifacts.
How can I keep the NVM updated node version available in the next stage?
This is not the first time that I have spent an exorbitant amount of time debugging bluemix, only to have switch to another provider that functions the way I need it to.
It turns out that by switching builder type to NPM and using the bluemix recommended script:
# To use Node.js 6.7.0, uncomment the following line:
export PATH=/opt/IBM/node-v6.7.0/bin:$PATH
the selected node version also is lost to the next stage of the pipeline, ie it has nothing to do with my long NVM script from above.