Select which Java JDK to use in Pipeline

Issue

  • You want to select which Java JDK to use in Pipeline

 

Environment

  • CloudBees Jenkins Enterprise
  • Pipeline plugin

 

Resolution

As an example, in case you have a node called vagrant-slave and the tool is called jdk-8u45. The below code is what you should use to set-up the JAVA_HOME.

node('vagrant-slave') {
    env.JAVA_HOME="${tool 'jdk-8u45'}"
    env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
    sh 'java -version'
}

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.