Configuring JDK in Jenkins

In the previous chapter, we learnt how to configure the Jenkins and start the server and see its GUI for other basic configurations. In this chapter will learn about configuring the JDK in Jenkins. Since Jenkins is commonly used for building and deploying the java applications, it offers excellent features for the same.

As a default one, Jenkins will use the java version which it find from the system path. This is which the Jenkins itself running under. However there may be scenarios where there is a need to configure more than one version of the JDK. Consider, in the production system the application might be running on JDK 5 and in some QA platform higher version of the JDK may be required in order to perform some specific tests e.g. performance issues.

As a best practice, it is always advisable to build the applications using the java version which is close to the version used in the production environment. Because, the application developed under JDK 5 can run easily with JDK 6 but the inverse of this may always have a high chance of failure.

Jenkins provides a good feature to configure multiple JVMs in order to overcome the above mentioned inverse java version issue.

Configuring JDK

Below are the steps to be followed in order to configure the JDK in Jenkins :

  1. Deploy the Jenkins.war into the tomcat server and start the server.
  2. From the home page, click on the link Manage Jenkins and click on Configure System as shown below :

    Configuring JDK in Jenkins

  3. From the next page, click on "Add JDK". The easiest way to configure JDK is to provide a name and path of the java installation directory. (Consider the same path used for JAVA_HOME). In the below screenshot JDK 6 and JDK 7 has been configured,

    Configuring JDK in Jenkins

    NOTE : The Jenkins will validate to check whether the installation directory exists for the specified JDK versions.
  4. JDK can also be installed by intimating Jenkins to do the task. The check box install automatically needs to be checked in this case. Jenkins will download and installs the specified version of the JDK into the tools directory of the Jenkins home directory.

    Configuring JDK in Jenkins

  5. After all the settings made to configure the JDK, just click the "Save" at the bottom of the page to save the configuration.