Last active
September 22, 2017 06:19
-
-
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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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