0

I am trying to change the version of Java used by Jenkins from Java 8 to Java 11. Jenkins is running on Windows Server 2016. I've installed the Java 11 SDK. I have tried creating a system environment variable JAVA_HOME pointing to my Java 11 installation (per instructions https://www.jenkins.io/doc/administration/requirements/upgrade-java-guidelines). I have also tried updating the Jenkins.xml file to point to the Java 11 installation. I was unable to access the Jenkins server after trying either of these methods (although it looked like the Jenkins service was running). How can I point my Jenkins service to my new Java 11 installation?

Jenkins was installed about a year ago using instructions in the Docs (https://www.jenkins.io/doc/book/installing/windows). It is installed as a service.

Current version: 2.346.3 Version of JDK installed: 11.0.16.1

The Java 8 version was installed (jre) with the original Jenkins install. The Java 11 version (JDK) was installed separately.

Here is my original Jenkins.xml file:

<service>
  <id>Jenkins</id>
  <name>Jenkins</name>
  <description>This service runs Jenkins automation server.</description>
  <env name="JENKINS_HOME" value="C:\Jenkins\Workspace"/>

 <!--if you'd like to run Jenkins with a specific version of Java, specify a full path to java.exe.
The following value assumes that you have java in your PATH.-->

  <executable>%BASE%\jre\bin\java</executable>
  <arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"</arguments>

  <logmode>rotate</logmode>

  <onfailure action="restart" /> 
   <extensions>
    <extension enabled="true" 
               className="winsw.Plugins.RunawayProcessKiller.RunawayProcessKillerExtension"
               id="killOnStartup">
      <pidfile>%BASE%\jenkins.pid</pidfile>
      <stopTimeout>10000</stopTimeout>
      <stopParentFirst>false</stopParentFirst>
    </extension>
  </extensions>  
</service>
PT2550
  • 136
  • 1
  • 11
  • How did you originally install Jenkins and as a service? Did you upgrade and how? From to what ver? I presume this is the JDK Jenkins runs under and you read [blog instructions](https://www.jenkins.io/blog/2022/06/28/require-java-11/) and not simply what [your jobs use](https://stackoverflow.com/questions/56842222/specify-java-home-in-jenkins-for-java-11/56843764#56843764) – Ian W Aug 30 '22 at 02:55
  • This totally depends on how you installed JDK in the Jenkins system. Did u try to restart your Jenkins after doing this? – sidharth vijayakumar Aug 30 '22 at 03:36
  • @Ian W, I don't recall the version originally installed but I've been running with 2.346.1 for some time without issue. I upgraded to 2.346.3 just before installing Java 11. Jenkins is running as a service. I followed upgrade instructions https://www.jenkins.io/doc/administration/requirements/upgrade-java-guidelines for the upgrade. – PT2550 Aug 30 '22 at 13:25
  • @sidharthvijayakumar, I installed the JDK separately from the Jenkins install. I stopped and started the Jenkins service after the install. – PT2550 Aug 30 '22 at 13:27
  • We are running Jenkins as a Windows service as well. I think you have to make sure that your new JDK is the first jenkins finds on the %PATH%. – DrHopfen Aug 30 '22 at 13:43
  • @DrHopfen, did you upgrade your Java version? Did you make any changes to the Jenkins.xml file? – PT2550 Aug 30 '22 at 16:57
  • @PT2550, yes, because newer jenkins complained Java8 support will end we wanted to switch to Java11. We did no changes to jenkins.xml. – DrHopfen Aug 30 '22 at 19:40
  • @DrHopfen, it sounds like you have successfully done what I am trying to do. However, when I created a JENKINS_HOME environment variable and added it to my Path (before any other Java installations), Jenkins still used the previous Java version. I saw that it was referenced in my Jenkins.xml file. If I change that reference, Jenkins doesn't start up properly. Could you tell me if your Jenkins.xml file references a Java version like mine does (see above)? – PT2550 Aug 30 '22 at 21:40

2 Answers2

0

Try to change this line

<executable>%BASE%\jre\bin\java</executable>

or change %BASE% variable. Also I would recommend to remove java 8 if it used only by jenkins.

Dmitriy Tarasevich
  • 1,082
  • 5
  • 6
0

I think our jenkins.xml is unmodified:

    <!--
    The MIT License

    Copyright (c) 2004-2017, Sun Microsystems, Inc., Kohsuke Kawaguchi, Oleg Nenashev, and other Jenkins contributors

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
    -->

    <!--
      Windows service definition for Jenkins.

      To uninstall, run "jenkins.exe stop" to stop the service, then "jenkins.exe uninstall" to uninstall the service.
      Both commands don't produce any output if the execution is successful. 
    -->
    <service>
      <id>jenkins</id>
      <name>Jenkins</name>
      <description>This service runs Jenkins automation server.</description>
      <env name="JENKINS_HOME" value="%BASE%"/>
     <!--
    if you'd like to run Jenkins with a specific version of Java, specify a full path to java.exe.
    The following value assumes that you have java in your PATH.
      -->
      <executable>java</executable>
    <arguments>-Xrs -Xmx1024m -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --webroot="%BASE%\war" --httpsPort=443 --httpsKeyStore="c:\path\to\keystore.jks" --httpsKeyStorePassword="****"    </arguments>
 
      <!--
    interactive flag causes the empty black Java window to be displayed.
    I'm still debugging this.
  <interactive />
  -->
  <logmode>rotate</logmode>

  <onfailure action="restart" />
  
  <!-- 
    In the case WinSW gets terminated and leaks the process, we want to abort
    these runaway JAR processes on startup to prevent corruption of JENKINS_HOME.
    So this extension is enabled by default.
  -->
  <extensions>
    <!-- This is a sample configuration for the RunawayProcessKiller extension. -->
    <extension enabled="true" 
               className="winsw.Plugins.RunawayProcessKiller.RunawayProcessKillerExtension"
               id="killOnStartup">
      <pidfile>%BASE%\jenkins.pid</pidfile>
      <stopTimeout>10000</stopTimeout>
      <stopParentFirst>false</stopParentFirst>
    </extension>
  </extensions>
  
  <!-- See the referenced examples for more options -->
  
</service>

I think the relavant hint is if you'd like to run Jenkins with a specific version of Java, specify a full path to java.exe. The following value assumes that you have java in your PATH.

So I just added JAVA11_HOME as a system variable and put %JAVA11_HOME%\binin front of the PATH system environment variable.

DrHopfen
  • 752
  • 3
  • 13