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' }
This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.