[EDIT (2016-06-02): OpenShift now provides different JDK “alternatives”, e.g.
So you might want to skip the steps bellow, regarding a custom JDK. The steps described for using a custom maven still apply, however.
In previous posts I pointed out how to build GitHub projects with Jenkins, Maven and SonarQube and how to run these builds on dedicated Jenkins slaves. The following shows how to replace the “stock” versions of maven and JDK that are provided by OpenShift.
At the time of writing OpenShift features Maven 3.0.4 and OpenJDK Server 1.7.0_85. Why would you want to change those? Best example is a Java8 project to be build on Jenkins. Can we just advise Jenkins to download the newest Oracle JDK and we’re good to go? Nope, it’s not that simple on OpenShift! Jenkins does download the new JDK, sets the
JAVA_HOME variable and the correct
PATH, but maven is always going to use the stock JDK. Why? Running this command provides the answer
$ cat `which mvn` #!/bin/sh prog=$(basename $0) export JAVA_HOME=/usr/lib/jvm/java export JAVACMD=$JAVA_HOME/bin/java export M2_HOME=/usr/share/java/apache-maven-3.0.4 exec $M2_HOME/bin/$prog "$@"
The stock maven is setting its own environment variables that cannot be overridden by Jenkins!
So, in order to exchange the JDK, we need to exchange maven first.
- SSH to the machines where your builds are executed (e.g. your slave node). The following example show what to do for maven 3.3.3:
cd $OPENSHIFT_DATA_DIR mkdir maven cd maven wget http://apache.lauf-forum.at/maven/maven-3/3.3.3/binaries/apache-maven-3.3.3-bin.tar.gz tar -xvf apache-maven-3.3.3-bin.tar.gz rm apache-maven-3.3.3-bin.tar.gz
- Edit maven config
Add the following to the
by your OpenShift UID first)
ibutton for edit mode, insert, then press
:wq, finally press return button)
- Browse to
Set Environment variables
- And that’s it, your builds are now running on the custom maven!
This allows for using a specific JDK in Jenkins. You could just choose a specific JDK via Jenkins console. This is comfortable, but has one disadvantage: It takes a lot of memory (approx. 600MB per JDK), because the JDK is stored twice – compressed in cache to be sent to slave and again uncompressed to be used on the master. If you got enough memory, you’re done here.
However, In case you’re running a small gear with only 1GB of memory, you might want to save a bit of your precious memory. The following example shows how to do so for JDK 8 update 51 build 16.
cd $OPENSHIFT_DATA_DIR mkdir jdk cd jdk wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-x64.tar.gz tar -xvf jdk-8u51-linux-x64.tar.gz rm jdk-8u51-linux-x64.tar.gz
- Then go to Jenkins
JDK installations | JDK