Bonzour

Jenkins Maven Plugin JDK

When setting up a Maven Jenkins job, you have the possibility of selecting a JDK in the options. This is great unless you want to set the JDK programatically in a pre-build shell script for example. To achieve the latter I did the following:

  1. Add a new JDK with path ‘${JAVA_HOME}’. You can do so in the Jenkins tool options. Name it something like ‘jdk_java_home_var’
  2. In your Maven Jenkins job, create a file named ‘${WORKSPACE}/env.properties’ and pipe into it:
    echo "JAVA_HOME=<new JDK location>" > ${WORKSPACE}/env.properties
    
  3. Load the environment variables from the env.properties file in a pre-build step
  4. Select the JDK to be ‘jdk_java_home_var’
  5. Save

That should be it!