Issue
A Pipeline job that requires a specific JDK.
Environment
- Jenkins
- Pipeline plugin
Resolution
Use the env.JAVA_HOME environment variable to specify the JDK to use as shown in the Pipeline snippet below:
node {
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'
}
0 Comments