node.jsjenkinsjenkins-pluginsjenkins-pipeline

How to use jenkins pipeline with nvm wrapper plugin?


I'm using pipeline (Jenkinsfile) and I need to change node version. i added the Nvm Wrapper Plugin but i don't know how to use it properly from Jenkinsfile

should i add the nvm('...') {} inside steps? or should it be somewhere top level in the node step? currently i don't even have the node step - everything is done using sh


Solution

  • what worked for me:

    pipeline {
      agent any
    
      stages {
        stage("Build") {
          steps {
             nvm(nvmInstallURL: 'https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh', 
                 nvmIoJsOrgMirror: 'https://iojs.org/dist',
                 nvmNodeJsOrgMirror: 'https://nodejs.org/dist', 
                 version: '8.1.2') {
                        sh "npm install"
                        echo "Build main site distribution"
                        sh "npm run build:dist"
                  }
               }
            }
        ...