Saturday, 2 May 2020

How to use different Node.js versions on Jenkins

If you need different version of Node.js and npm to build your application, you can configure them directly on Jenkins, with these simple steps.


1) Download NodeJS plugin for Jenkins.


The documentation about the plugin is available here


2) Configure the plugin.

Go to Manage Jenkins -> Global tools configuration and find NodeJS section.
Select the version you need and name it as you prefer. You can also add npm packages that needs to be installed globally.

Here's an example:



You can add several NodeJS installation, depending on your needs.


3) Configure your (declarative) pipeline.

To use node and npm commands, add the following step in you Jenkinsfile:


stage('Review node and npm installations') {
  steps {
    nodejs(nodeJSInstallationName: 'node13') {
      sh 'npm -v'  //substitute with your code
      sh 'node -v'
    }
  }
}






13 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. href="https://istanbulolala.biz/">https://istanbulolala.biz/
    WD70XR

    ReplyDelete