Jenkins pipeline : select nodejs version (+ python version)

前端 未结 3 1364
礼貌的吻别
礼貌的吻别 2021-02-20 02:34

I\'m facing an issue with a Jenkins pipeline in a Jenkinsfile. I have 4 different nodeJs versions on my Jenkins instance. I would like to choose which one I\'m going to use in m

相关标签:
3条回答
  • 2021-02-20 03:17

    So. This is a problem from "EnvInject" plugin: https://issues.jenkins-ci.org/browse/JENKINS-26583

    My workaround #4 above is the correct solution if you want to keep EnvInject.

    env.NODE_HOME="${tool 'Node 6.x'}"
    env.PATH="${env.NODE_HOME}/bin:${env.PATH}"
    sh 'npm -version'
    

    Otherwise, removing EnvInject plugin is also a good solution when possible.

    0 讨论(0)
  • 2021-02-20 03:22

    how about using docker image with the specific version of node and/or python in your Jenkins pipeline? this would be a clean solution since you will only need to install docker on the build machine and not side-by-side versions of python.

    https://jenkins.io/doc/book/pipeline/docker/

    0 讨论(0)
  • 2021-02-20 03:24
    pipeline {
         agent {
                    label 'slave-machine'
        }
        environment {
            NODE_HOME = tool name: 'Node 10.13.0', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
        }
        stages { 
            stage('test') {]
                steps {
                   script {
                       env.PATH="${env.NODE_HOME}/bin:${env.PATH}"
                       sh 'node -v'
                       sh 'echo $NODE_HOME'
                   }
                }
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题