How to use a different nodejs version on atlassian bamboo build agent

  • fennng 

When you build a nodejs app, you may need to use a specific version of node for building. Either you want to match the running env or your node packages require a certain nodejs version.

On Azure DevOps, you can easily choose the node version by adding a nodejs installer step. With bamboo, there is no nodejs install, but this can be achieved easily if you have admin access to the build agent.

In the build steps, add a script step, and add the following inline script. This script will switch the node version for you. For first time running, you need to uncomment all the lines to install nvm first.


node -v
#curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
#nvm install 13.6.0
nvm use 13.6.0
nvm list
node -v

Then you can add a npm install step, it will use the new node version. Or you can simply add node install command to the script.

More about nvm, read this https://github.com/nvm-sh/nvm/blob/master/README.md

发表评论

您的电子邮箱地址不会被公开。