Resolution
As an example, in case you have a node called vagrant-agent and the tool is called jdk-8u45. The below code is what you should use to set-up the JAVA_HOME.
node('vagrant-agent') { env.JAVA_HOME="${tool 'jdk-8u45'}" env.PATH="${env.JAVA_HOME}/bin:${env.PATH}" sh '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.