2

I want to deploy an angular 2 app on bluemix. The code is located at github and i want to deploy my app when i push something. So i created a pipeline. First the build pipeline: to build the angular app i need angularCLI, so i want to install it. Unfortunately the default node version is 4.2 but the cli needs at least 6.9. Here is my build-shell-command:

#!/bin/bash
# The default Node.js version is 0.10.40
# To use Node.js 0.12.7, uncomment the following line:
#export PATH=/opt/IBM/node-v0.12/bin:$PATH
# To use Node.js 4.2.2, uncomment the following line:
export PATH=/opt/IBM/node-v6.9/bin:$PATH
npm install -g @angular/cli
npm run build

I tried to replace 4.2 with 6.9 but it doesnt work and it uses the default node version 0.10.40. Anyone know how to set the node version? Also the npm version is out of date... how can i fix this?

ralphearle
  • 1,696
  • 13
  • 18
J. Doe
  • 71
  • 5

2 Answers2

6

The answer above pointed me in the right direction, but newer versions of NVM wouldn't work. NVM's install.sh now checks if NVM_DIR is set but the directory doesn't exist.

I changed the NVM_DIR path and declared it after install.sh has completed.

bash
#!/bin/bash

export NODE_VERSION=8
export NVM_VERSION=0.33.11

npm config delete prefix \
  && curl -o- https://raw.githubusercontent.com/creationix/nvm/v${NVM_VERSION}/install.sh | bash \
  && export NVM_DIR="$HOME/.nvm" \
  && . $NVM_DIR/nvm.sh \
  && nvm install $NODE_VERSION \
  && nvm alias default $NODE_VERSION \
  && nvm use default \
  && node -v \
  && npm -v
Nick VanderPyle
  • 2,939
  • 3
  • 26
  • 33
5

Ok, bluemix just provide a few versions of node and npm... Found the solution at http://gh-blog.mybluemix.net/blogs/cokeSchlumpf/rethink-it/posts/bluemix/node-buildpipeline.md?cm_mc_uid=01575932457714863658655&cm_mc_sid_50200000=1487233177

#!/bin/bash
export NVM_DIR=/home/pipeline/nvm
export NODE_VERSION=5.10.1
export NVM_VERSION=0.29.0

npm config delete prefix \
  && curl https://raw.githubusercontent.com/creationix/nvm/v${NVM_VERSION}/install.sh | sh \
  && . $NVM_DIR/nvm.sh \
  && nvm install $NODE_VERSION \
  && nvm alias default $NODE_VERSION \
  && nvm use default \
  && node -v \
  && npm -v

npm install
# Further steps ...
J. Doe
  • 71
  • 5
  • This [commit on Jan 6th, 2018](https://github.com/creationix/nvm/commit/7cba6cd6d0dc0a126f12360d0523afe0c0bf9fce) stops the install if NVM_DIR is set but the path isn't valid. The script [in my answer](https://stackoverflow.com/a/50728769/62054) seems to work, for now. :) – Nick VanderPyle Jun 06 '18 at 20:13