How to change the JDK for a Jenkins job?
Asked Answered
I

11

67

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.

Intra answered 2/3, 2015 at 13:2 Comment(0)
S
50

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.

Schmaltz answered 2/3, 2015 at 13:5 Comment(11)
This, we will get while created new job but not while editing the existing job. I might be wrong as I have just started to configure jenkins.Intra
It is also configurable in existing jobs. Open the Jenkins web ui, go into the job configuration - the JDK dropdown in one of the first configuration items.Schmaltz
Sorry, i am not able to find it. The config sections I have are: Advanced Project Options, Source Code Management, Build Triggers, Pre Steps, Build, Post Steps, Build Settings, Post-build Actions.Intra
Is this a maven project? You should see "common" configs like Maven project name, Description etc right at the top of the Configuration page - this section includes JDK in my Jenkins.Schmaltz
Yes, It is Maven Project. You can have a look at snapshot I have updated in the question.Intra
I am getting the JDK drop down in my old jenkins UI. Now sure why it is available in the new one.Intra
Got it. I had error while configuring the JDK location in the manage jenkins section because of which it didn't have anything to show in the dropdown.Intra
latest Jenkins version 2.7.4 is: Manage Jenkins -> Global Tool Configuration -> JDKTortuous
Just a comment for explaining details: if you configured JDK correctly and you have more than one JDK configured in your Jenkins, you can easily find it in job-configure.Rookie
Is it possible the if there is only one jdk it does not show the option in project and take that one which is set?Nibelung
It seems jdk option is not available while edit if there is only one jdk in Jenkins.Nibelung
C
48

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

Cantone answered 23/3, 2016 at 10:49 Comment(5)
yes that 's right, but even the JDK dropdown occurred, the build always get error for maven cannot find the javaAuspicious
still a problem in 2.107.3 ... just wasted 30mins of my lifeBisk
The above workaround solved my issue. Still an issue in 2.138.3Semiquaver
Exactly! I had to add another JDK in the Global Config section, and then it showed up in the job deployment config section. Thanks a lot.Citrin
It seems this is true. Job is working but no jdk option is available.Nibelung
D
23

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

Douse answered 2/3, 2015 at 13:27 Comment(5)
I am getting the JDK drop down in my old jenkins UI. Not sure why it is available in the new oneIntra
Are JDKs configured in Manage Jenkins -> Configure System -> JDK installations?Schmaltz
Got it. I had error while configuring the JDK location in the manage jenkins section because of which it didn't have anything to show in the dropdown.Intra
There is no such JDK section.Mireyamiriam
The JDK section is in Manage Jenkins -> Global Tool Configuration now.Justiciar
S
18

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.

Springs answered 21/9, 2016 at 5:44 Comment(2)
Restart was key, so this answer combined with the @Schmaltz answer did the trick for me. (Using Jenkins v2.32.3)Foredoom
This doesn't work for pipeline projects - so had to explicity reference JDK version in jenkinsfilePolyzoic
M
5

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]

Mikiso answered 3/11, 2015 at 15:36 Comment(1)
This is similar to my experience with Jenkins 1.647, however in my case JDK1 was an explicitly named JDK. Only when I added a second did I get the option to specify the "JDK to be used for this project" and got the three optionsSoakage
M
4

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.

Maziemazlack answered 6/9, 2021 at 12:51 Comment(0)
B
3

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

Bassoon answered 5/9, 2018 at 9:28 Comment(0)
G
1

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.

Guernica answered 19/11, 2015 at 18:33 Comment(0)
K
1

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

Kimberly answered 4/7, 2017 at 17:9 Comment(0)
V
0

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

Volvulus answered 1/9, 2021 at 7:46 Comment(0)
E
0

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

Ethology answered 11/11, 2022 at 17:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.