How to change the JDK for a Jenkins job?

JavaJenkins

Java Problem Overview


enter image description hereI have imported the jenkins jobs from existing jenkins server from another machine. But the problem is, it has the JDK referenced as per the old machines and I want to change it to use the JDK configured in my new jenkins. But I am unable to find any way of doing this. So, please if you have come across this situation and found a way then please help me too.

Thanks.

Java Solutions


Solution 1 - Java

There is a JDK dropdown in "job name" -> Configure in Jenkins web ui. It will list all JDKs available in Jenkins configuration.

Solution 2 - Java

For existing jobs you're editing, the JDK drop-down choice may not be available if you've just added a single JDK config in the 'Configure System' Jenkins settings.

However, it is available for new jobs.

Surprisingly, if you add a second JDK config, it becomes available in an existing job too.

This looks to me like a bug (tested in Jenkins ver. 1.629).

See a similar issue raised here: JDK selection is hidden even when a JDK is configured

Solution 3 - Java

Here is where you should configure in your job:

In JDK there is the combobox with the different JDK configured in your Jenkins. Job

Here is where you should configure in the config of your Jenkins:

Jenkins general config

Solution 4 - Java

Using latest Jenkins version 2.7.4 which is also having a bug for existing jobs.

  1. Add new JDKs through Manage Jenkins -> Global Tool Configuration -> JDK ** If you edit current job then JDK dropdown is not showing (bug)

  2. Hit http://your_jenkin_server:8080/restart and restart the server

  3. Re-configure job

Now, you should see JDK dropdown in "job name" -> Configure in Jenkins web ui. It will list all JDKs available in Jenkins configuration.

Solution 5 - Java

Here is my experience with Jenkins version 1.636: as long as I have only one "Install automatically" JDK configured in Jenkins JDK section, I don't see "JDK" dropdown in Job=>Configure section, but as soon as I added second JDK in Jenkins config, JDK dropdown appeared in Job=>Configure section with 3 options [(System), JDK1, JDK2]

Solution 6 - Java

If you have a multi-config (matrix) job, you do not have a JDK dropdown but need to configure the jdk as build axis.

Solution 7 - Java

Hello it is possible set a new JDK in old job, if you use the Pipeline. You just write something like this:

pipeline{
 agent any
 tools{
     jdk 'deafault'
 }
 stages{ 
    stage('build'){
       ..............
       }
    } 
 } 
}

Where default is just the name that you give to the JDK when you config it in the Jenkins configuration Global System.

Solution 8 - Java

Be careful with jobs

1 - if you have a job based in maven, Jenkins takes your default java configuration and you decide the compilation level in your POM.XML.

2 - if you have a free style job, in the the configuration option of the job you can select the JDK that you want to use.

Hope this help.

Solution 9 - Java

For those who couldn't find this option. Install JDK Parameter Plugin

Solution 10 - Java

I had the same issue (running Jenkins v2.303.1) and I needed to add new JDKs before I saw them in the project settings.

Go to "Manage Jenkins (in german: Jenkins verwalten)", then "Configuration of tools (in german: Konfiguration der Hilfsprogramme)" and there should be a section regarding "JDK". Here, you can manage your different java versions (whether to download or use local ones): Picture of JDK section

After setting these JDKs I was able to choose which JDK version to use: JDK choose option

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGuruKulkiView Question on Stackoverflow
Solution 1 - JavanomisView Answer on Stackoverflow
Solution 2 - JavaRZetView Answer on Stackoverflow
Solution 3 - JavaIker AguayoView Answer on Stackoverflow
Solution 4 - JavaJitesh SojitraView Answer on Stackoverflow
Solution 5 - JavadymyView Answer on Stackoverflow
Solution 6 - JavaHorst KrauseView Answer on Stackoverflow
Solution 7 - JavaAzazzelloView Answer on Stackoverflow
Solution 8 - JavaAntuanSoftView Answer on Stackoverflow
Solution 9 - JavaGennadiy RyabkinView Answer on Stackoverflow
Solution 10 - JavaIVIikeView Answer on Stackoverflow