Using OpenJDK 12 in Jenkins (Docker version) - java

I tried to install OpenJDK 12 in jenkins, with *.tar.gz installer but i get the error Cannot run program "/bin/java"
JAVA_HOME=/var/jenkins_home/tools/hudson.model.JDK/java12
Note I created the directory "hudson.model.JDK" myself.
here is the tool configuration
full error log

JDK 12 has one bug logged
https://bugs.openjdk.java.net/browse/JDK-6746185
according to this Malformed URL is invalid, So jenkins is not able to download JDK
Simple solution is download JDk from this link, or whatever you like and add Open JDK in jenkins as I do
https://download.java.net/java/GA/jdk12.0.1/69cfe15208a647278a19ef0990eea691/12/GPL/openjdk-12.0.1_linux-x64_bin.tar.gz
Download JDK and extract it to one folder.
Manage Jenkins> Global Configurations> Add JDK>
1. Name: Open JDK(Or whatever you want)
2. JAVA_HOME: \Open_JDK\
like in my case
E:\Open_JDK\openjdk-11.0.2_windows-x64_bin\jdk-11.0.2
in jenkins
Save and exit, everything working fine
Happy Jenkins, Happy to help

JDK Tool Plugin in Jenkins only support the automatic download of version up to Java SDK 1.9 so I will write the process made by me in order to config OpenJDK-11(I'm using this specific version but another version can be used) in a Jenkins running in a Docker container:
Login into the host server where the docker container is running using SSH
service.
Check the running containers with the command: docker ps
Get in into the Jenkins container with the command(in my case, the container name is "jenkins"): docker exec -it containerName /bin/bash
Download the OpenJDK 11: cd /usr/local && wget https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_linux-x64_bin.tar.gz
Unpack the downloaded file: tar -zxvf openjdk-11+28_linux-x64_bin.tar.gz
Now you will have a folder "jdk-11" under /usr/local.
Go to Global Tools Configuration in Jenkins and set up the SDK config like the showed image:
Now you can make use of a different version of Java SDK in Jenkins builds using as label "Java SE 11".

JDK 12 is not yet supported by Jenkins.
Link: https://jenkins.io/doc/administration/requirements/java/

Related

How to install Git on the standard openjdk docker image?

Recently started upgrading my app from JDK 8 to 17.
My build infrastructure uses docker containers. Previously, I was using openjdk:8u322-jdk. So I bumped the docker image to openjdk:17.0.2-jdk, but things've changed drastically.
There's no Git installed by default now, I think the underlying OS has changed and the default CMD is "jshell", whatever that is o_O
I don't want to spend time faffing about creating my own docker image with the needed tools installed.
At the end of the day, I just need to run two commands on the build container: git clone and gradlew.
What do I need to run to get Git installed so I can run a git clone and gradlew?
microdnf install git to install git.
Need to execute bash explicitly if you want to connect and run commands.

Running Jenkins Node/Agent as a Windows Service with OpenJDK

I have a Windows virtual machine with OpenJDK 13 installed that I would like to setup as a Jenkins node/agent.
When I create the node configuration using the Jenkins UI and select Launch Method: Launch Agent by connecting it to the master it provides a link to download slave-agent.jnlp
On a system with the original jdk/jre older than version 9, which contains java web start, if I run that jnlp file, it brings up a window with a menu that includes an option File - Install as A Service
However, as OpenJDK (and I believe any JRE/JDK versions greater than 8) do NOT contain Java Web Start, I cannot seem to gain access to that option.
I am able to successfully run java -jar agent.jar -jnlpUrl https://jenkinsserver/blah/slave-agent.jnlp -secret blah -workDir "somedirectory" and have the node register with Jenkins, but it is not running as a service.
I had an older agent that was still using old version of JRE, so I looked at its Jenkins service configuration and unfortunately it seems to be relying on executable(s), .config file(s), and xml file(s), which I cannot determine the source of, beyond they must be created when running the "Install as a service" instructions from slave-agent.jnlp
I also attempted to use IcedTea-Web which is apparently supposed to be a Java Web Start replacement, but I've had no success.
Can anyone tell me how to setup a Windows machine running OpenJDK as a Jenkins node/agent with the Jenkins node/agent components running as a Windows service?
I had a similar issue and now I use NSSM.
Download NSSM
Open a cmd and install the service (I used JenkinsService as Servicename):
<path to nssm.exe>\nssm install <Servicename>
Insert the path to the jdk to the field Path
add the rest to the field Arguments:
-jar agent.jar -jnlpUrl https://jenkinsserver/blah/slave-agent.jnlp -secret blah -workDir "somedirectory"
Click on install the service
Now you can check the new service JenkinsService in the windows service manager. As soon as it's running you can check the connection to the master.
If you want to setup a Java base application as a service, I believe the best option would be to use Procrun from Apache. It is the exact method that Tomcat uses.

Start Jenkins with JDK 8 without changing system java_home

I have Jenkins 2.46.3 LTS version that i am trying to upgrade to 2.73.3 LTS version. My current java version is 1.7. How do i install and start Jenkins with 1.8 version? I am getting the following error after i copied Jenkins war file under (/usr/lib/Jenkins) and restarted the service
$ sudo service jenkins start
Starting Jenkins Jenkins requires Java8 or later, but you are running 1.7.0_97-b02 from /app_2/java/jdk1.7.0_97/jre
java.lang.UnsupportedClassVersionError: 51.0
at Main.main(Main.java:124)
Is there any way to start Jenkins using Java 8 without changing the system classpath?
Thanks,
Ann
Set JENKINS_JAVA option in /etc/sysconfig/jenkins file.
The variable name might be different depending on your operating system and package source but the /etc/sysconfig/jenkins file is usually the configuration file for your jenkins service.
Just run the war with the new java binary:
nohup <path to your new jdk8 folder>/java -jar jenkins.war > $LOGFILE 2>&1
Not sure if JAVA_HOME is needed, but you can execute the line below in the shell, before the command above, or add to the top of init script :
export JAVA_HOME=<path to your new jdk8 folder>/java
Hope that helps.

Can't access third party repo using yum in Azure RHEL node

We have provisioned a RHEL server from Azure. I understand that our infrastructure guys are a bit strict on access.
We need to install Oracle JDK in this machine and it looks like wget is not an option on getting rpms, only yum. However, I need to enable Third-party repo like Oracle in order to yum install a JDK, so I issued this command:
subscription-manager repos --enable rhel-7-server-thirdparty-oracle-java-rpms
and I get
Network error, unable to connect to server. Please see /var/log/rhsm/rhsm.log for more information
When I do yum update and yum install telnet, it seems to do its job.
My question is, do I have an alternative in getting JDK installed? For those who are knowledgeable about Azure and networking configuration, what specific request should we ask from our infrastructure people to enable "download"?
Per my experience, i think the issue may be caused by the VM network. But, this has not problems when you run yum update. So i suggest that you can run ping www.microsoft.com in the VM terminal to inspect whether your VM can connect to extranet.
For your first question, we can use an alternative method to install oracle JDK on RHEL.
1.You could download the Oracle JDK(.tar.gz) from Oracle official website just as below.
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
2.You could upload JDK package which you have downloaded to your Azure VM directory by ftp tools like FileZilla.
description image
3.You could use SecureCRT to connect to Azure VM.
description image
4.
Install java with alternatives.
#cd /home/johnny
#tar -zxf jdk-7u79-linux-x64.tar.gz -C /opt/
#cd /opt/jdk1.7.0_79/
#alternatives --install /usr/bin/java java /opt/jdk1.7.0_79/bin/java 2
#alternatives --config java
the output may be below:
description image.
you could input 1 to continue.
5.Now, you may also require to set up javac and jar commands path using alternative commands.
#alternatives --install /usr/bin/jar jar /opt/jdk1.7.0_79/bin/jar 2
#alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_79/bin/javac 2
#alternatives --set jar /opt/jdk1.7.0_79/bin/jar
#alternatives --set javac /opt/jdk1.7.0_79/bin/javac
6. Check installed java version.
#java -version
description image
7.Configuring environment variables.
Setup JAVA HOME variable:
#export JAVA_HOME= /opt/jdk1.7.0_79
Setup JRE HOME variable:
#export JRE_HOME=/opt/jdk1.7.0_79/jre
Setup PATH variable:
#export PATH=$PATH:/opt/jdk1.7.0_79/bin:/opt/jdk1.7.0_79/jre/bin
There is another method to config environment variables.
Modify the config file: /etc/profile. In this method, anyone who has logged in can use java.
description image
8.The refference:
http://tecadmin.net/steps-to-install-java-on-centos-5-6-or-rhel-5-6/#
For your second question, you can ask some problems about azure network config.
Hope it helps. Any concerns, please feel free to let me know.

Jenkins, specifying JAVA_HOME

I installed openjdk-6-jdk on my ubuntu box using apt-get.
In system info jenkins is telling me Java.Home is /usr/lib/jvm/java-6-openjdk/jre
However when I specify that directory as JAVA_HOME in Jenkins : "configure system", it returns error message saying that directory does not look like a jdk directory.
it is also failing to pick up my maven install.
Am I missing something obvious ?
Your JAVA_HOME variable must be set to /usr/lib/jvm/java-6-openjdk and it must be available for the user that starts Jenkins.
From Kyle Strand comment:
As of April 2015 (I think), Jenkins requires Java7. Also note that the java binary path (JAVA) must be set to the correct version if the system default is still Java 6. Finally, for anyone wondering where these variables are set, it's in a config file listed with the installation instructions on the Jenkins webpage (e.g. for Debian it's /etc/default/jenkins).
Using Jenkins 2 (2.3.2 in my case), the right way seems to insert the following into your pipeline file:
env.JAVA_HOME="${tool 'jdk1.8.0_111'}"
env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
"jdk1.8.0_111" beeing the name of the java configuration initially registered into Jenkins
On CentOS 6.x and Redhat 6.x systems, the openjdk-devel package contains the jdk. It's sensible enough if you are familiar with the -devel pattern used in RedHat, but confusing if you're looking for a jdk package that conforms to java naming standards.
I was facing the same issue and for me downgrading the JAVA_HOME from jdk12 was not the plausible option like said in the answer. So I did a trial and error experiment and I got the Jenkins running without even downgrading the version of JAVA_HOME.
Steps:
open configuration $ sudo vi /etc/init.d/jenkins
Comment following line:
#JAVA=`type -p java`
Introduced the line mentioned below. (Note: Insert the specific path of JDK in your machine.)
JAVA=`type -p /usr/lib/jdk8/bin/java`
Reload systemd manager configuration: $ sudo systemctl daemon-reload
Start Jenkins service: $ sudo systemctl start jenkins
● jenkins.service - LSB: Start Jenkins at boot time
Loaded: loaded (/etc/init.d/jenkins; generated)
Active: active (exited) since Sun 2020-05-31 21:05:30 CEST; 9min ago
Docs: man:systemd-sysv-generator(8)
Process: 9055 ExecStart=/etc/init.d/jenkins start (code=exited, status=0/SUCCESS)
I just wanted to add a solution for Windows machines.
Windows Server 2008 R2 Standard, SP1
Jenkins 2.89.4
Java version 8.171
Symptom: Jenkins service starts and immediately stops.
Jenkins.wrapper.log has a line indicating the incorrect path to Java:
- Starting C:\Program Files\Java\jre1.8.0_141\bin\java -Xrs -Xmx6g -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "C:\Program Files (x86)\Jenkins\jenkins.war" --httpPort=8080 --webroot="C:\Program Files (x86)\Jenkins\war"
The fix: Jenkins has the path hard-coded in jenkins.xml. Change the path to the new Java location.
<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>C:\Program Files\Java\jre1.8.0_171\bin\java</executable>
<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"</arguments>
You can also use Windows Environment Variables, but I wasn't successful with that and I don't think the Java installer updates those, so you'd need to update that by hand every time anyway.
<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_HOME%\bin\java</executable>
<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"</arguments>
openjdk-6 is a Java runtime, not a JDK (development kit which contains javac, for example). Install openjdk-6-jdk.
Maven also needs the JDK.
[EDIT] When the JDK is installed, use /usr/lib/jvm/java-6-openjdk for JAVA_HOME (i.e. without the jre part).
This is an old thread but for more recent Jenkins versions (in my case Jenkins 2.135) that require a particular java JDK the following should help:
Note: This is for Centos 7 , other distros may have differing directory locations although I believe they are correct for ubuntu also.
Modify /etc/sysconfig/jenkins and set variable JENKINS_JAVA_CMD="/<your desired jvm>/bin/java" (root access require)
Example:
JENKINS_JAVA_CMD="/usr/lib/jvm/java-1.8.0-openjdk/bin/java"
Restart Jenkins (if jenkins is run as a service sudo service jenkins stop then sudo service jenkins start)
The above fixed my Jenkins install not starting after I upgraded to Java 10 and Jenkins to 2.135
java jenkins java-home ubuntu centos
For those of you coming to this issue and have access to configure your Jenkins Agents, you can set the JAVA_HOME from the Jenkins > Nodes > "the agent name" > Configure page:
Setting "per agent" environment variables
In case anyone has similar problems, I used the default sudo apt-get installs for the relevant packages and here are the correct settings:
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
and
MAVEN_HOME=/usr/share/maven2
In Jenkins try setting JAVA_HOME to /usr/lib/jvm/java-6-openjdk
Upgrading from Ubuntu 10.0.4 to 12.0.4 we got wrong footed.
We had a JDK installation configured (auto-configured?) pointing to /usr/lib/jvm/java-6-openjdk
this no longer contained a JDK,
Changing to /usr/lib/jvm/default-java fixed, and should make for a seamless java-7 upgrade.
So in answer to the question: do not specify JAVA_HOME on Ubuntu.
In Ubuntu 12.04 I had to install
openjdk-7-jdk
then javac was working !
then I could use /usr/lib/jvm/java-7-openjdk-amd64 as path and jenkins didn't complain anymore.
Download package rpm package from http://pkg.jenkins-ci.org/redhat/ you can give additional java location like I have default 1.7 java in my system but I am using /opt/jdk1.8.0_60/bin/java for jenkins. Open jenkins startup script /etc/init.d/jenkins and add additional java here, I m case I have added /opt/jdk1.8.0_60/bin/java,
Search usable Java as /usr/bin/java might not point to minimal version required by Jenkins.
See http://www.nabble.com/guinea-pigs-wanted-----Hudson-RPM-for-RedHat-Linux-td25673707.html
candidates="
/opt/jdk1.8.0_60/bin/java
i saw into
Eclipse > Preferences>installed JREs > JRE Definition
i found the directory of java_home
so it's
/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home

Categories