kor_
kor_

Reputation: 1530

Is it safe to run "Node.js Tool installer task" multiple times on Azure Devops hosted agent?

We have a dedicated server for Azure Devops hosted agents. The server runs all the pipelines we have. Now we have run into an issue where one project requires node.js version 8, and one project requires version 10 or 12.

So we can't just update the node.js installation on the server.

Microsoft offers the Node.js Tool installer task, but the description says it will add it to the PATH environment variable. We haven't run the installer task yet (don't want to break the builds).

Has anyone tried installing multiple versions of node.js on one server? Is it possible? Or is the task only meant to be used in a hosted (short-lived) build agent?

Upvotes: 0

Views: 2096

Answers (2)

Krzysztof Madej
Krzysztof Madej

Reputation: 40603

This is fine and it is also mention in troubleshoot section

If you're using nvm to manage different versions of Node.js, consider switching to the Node Tool Installer task instead. (nvm is installed for historical reasons on the macOS image.) nvm manages multiple Node.js versions by adding shell aliases and altering PATH, which interacts poorly with the way Azure Pipelines runs each task in a new process. The Node Tool Installer task handles this model correctly. However, if your work requires the use of nvm, you can add the following script to the beginning of each pipeline:

steps:
- bash: |
    NODE_VERSION=12  # or whatever your preferred version is
    npm config delete prefix  # avoid a warning
    . ${NVM_DIR}/nvm.sh
    nvm use ${NODE_VERSION}
    nvm alias default ${NODE_VERSION}
    VERSION_PATH="$(nvm_version_path ${NODE_VERSION})"
    echo "##vso[task.prependPath]$VERSION_PATH"

Then node and other command-line tools will work for the rest of the pipeline job. In each step where you need to use the nvm command, you'll need to start the script with:

- bash: |
    . ${NVM_DIR}/nvm.sh
    nvm <command>

So to sum up it is fine to use Node Tool Installer but if you decide to use nvm pleace keep in mind above comments.

Upvotes: 1

myeongkil kim
myeongkil kim

Reputation: 2576

How about using nvm
It's a good tool to support multiple versions of node.js. It is used a lot.

for example

nvm install v8
nvm install v10
nvm install v12
# first terminal
nvm use 8 
npm install 
node node_v8_server.js
# second terminal
nvm use 10
npm install
node node_v10_server.js
# third terminal
nvm use 12
npm install
node node_v12_server.js

Upvotes: 0

Related Questions