54
votes

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.

10

10 Answers

39
votes

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

33
votes

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

20
votes

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

14
votes

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.

5
votes

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]

3
votes

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

1
votes

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.

1
votes

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.

0
votes

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

0
votes

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