Skip to content

Instantly share code, notes, and snippets.

@perfectfoolish
Last active September 22, 2017 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perfectfoolish/b5b36fa19e3bdd9b11b3e48261176b73 to your computer and use it in GitHub Desktop.
Save perfectfoolish/b5b36fa19e3bdd9b11b3e48261176b73 to your computer and use it in GitHub Desktop.
Use the env.JAVA_HOME environment variable to specify the JDK to use as shown in the Pipeline snippet below:
node {
// https://support.cloudbees.com/hc/en-us/articles/115001595227-How-To-Specify-A-Specific-JDK-In-Pipeline-
// configure the JDK in Manage Jenkins > Global Tool Configuration > JDK
jdk = tool name: 'JDK17'
env.JAVA_HOME = "${jdk}"
echo "jdk installation path is: ${jdk}"
// next 2 are equivalents
sh "${jdk}/bin/java -version"
// note that simple quote strings are not evaluated by Groovy
// substitution is done by shell script using environment
sh '$JAVA_HOME/bin/java -version'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment