GuruKulki
GuruKulki

Reputation: 26418

How to change the JDK for a Jenkins job?

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.

Upvotes: 68

Views: 176342

Answers (11)

Kumar Pankaj Dubey
Kumar Pankaj Dubey

Reputation: 2307

you should only add this path to Manage Jenkins -> Global Tool Configuration -> JDK

for java 11

/usr/lib/jvm/java-11-openjdk-amd64

for java 8

/usr/lib/jvm/java-8-openjdk-amd64

Upvotes: 0

nomis
nomis

Reputation: 2715

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

As per @Derek comment below, n newer versions, you can find it in Manage Jenkins -> Global Tool Configuration -> JDK.

Note that you need the "Overall/Administer" permission to manage Jenkins.

Upvotes: 51

IVIike
IVIike

Reputation: 117

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

Upvotes: 0

Azazzello
Azazzello

Reputation: 41

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.

Upvotes: 4

Horst Krause
Horst Krause

Reputation: 686

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

Upvotes: 3

AntuanSoft
AntuanSoft

Reputation: 353

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.

Upvotes: 1

Henadzi Rabkin
Henadzi Rabkin

Reputation: 7043

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

Upvotes: 1

Jitesh Sojitra
Jitesh Sojitra

Reputation: 4043

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.

Upvotes: 18

RZet
RZet

Reputation: 1074

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

Upvotes: 49

dymy
dymy

Reputation: 71

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]

Upvotes: 5

Iker Aguayo
Iker Aguayo

Reputation: 4115

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

Upvotes: 23

Related Questions