简体   繁体   中英

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

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"
              }
           }
        }
    ...

I ended up using this and it works also with a .nvmrc file

sh 'bash -l -c ". $HOME/.nvm/nvm.sh ; nvm use || nvm install && nvm use"' 

This expects nvm installed in the jenkins home folder. But it would be easy to add a step that downloads nvm in the right place first.

this works for me

sh 'bash -l -c ". $HOME/.nvm/nvm.sh ; nvm use <version> || nvm install <version> && nvm use <version> "' 

example:

sh 'bash -l -c ". $HOME/.nvm/nvm.sh ; nvm use 8.0 || nvm install 8.0 && nvm use 8.0 "' 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM