Johannes' Blog

Struggeling with Eclipse…

Jenkins Setup on OpenShift

A while ago I decided to setup a Jenkins CI server and Demo Instance for  Jabylon Translation Server on free of charge OpenShift servers. OpenShift already comes with built-in support for this kind of setup, which is really cool, but not exactly what I had wanted, because the workflow is meant for the OpenShift Git repository. Since Jabylon is hosted on Github and I am very happy with their services, I ended up configuring things a little differently than the OpenShift defaults. The setup I had in mind meant an OpenShift gear with a Jenkins instance that automatically builds Jabylon on every Git push and a second gear that hosts the demo instance and automatically updates the software every 24 hours.

Getting to this point required a bit of trial and error, primarily because I did not have much experience with OpenShift so far and there is quite a few pitfalls when running on an restricted environment like the OpenShift gears.This is not going to be a general OpenShift tutorial, since you can find those better elsewhere, I am focusing and what needs to be done if you want to build and run a DIY application that is not hosted in the gear internal Git repository, but by another repository provider like Github.

Getting Started

To get started you first need to register at OpenShift to get your account set up. Once that is all set, you need to create a Jenkins application on one of the gears. This can either be done from command line, or directly in the web interface. Once that is done, you can create a new DIY application that will host the demo instance of your application. Now 2 of your 3 free gears are used, and here comes the first difference to the default OpenShift workflow.

Normally, you would now enable the Jenkins Client Cartridge on your DIY application and that would do automatically create a pre-configured build job in your Jenkins application. However, this build job did not do the trick for me, because it depends on you using the Git repository of your DIY application to host your source code. Also, the build job is not going to be a maven job, but a freestyle job that invokes a shell script (that triggers the default build script of your DIY application).

Instead, I went without the jenkins client cartridge and a manually configured maven build job. However, the pre-configured version of Jenkins comes with no build queues! From my experience, the build slave seems to be a necessity because the small gear is not powerful enough for a complex maven build while running the jenkins server at the same time. So I utilized my third gear for another DIY application that is going to be the a jenkins build slave. This slave is going to be be connected to the Jenkins gear as a regular SSH slave node. That means, you will need to upload your OpenShift private key to the Jenkins gear and reference it in the slave conifguration. One way to do this is by simply uploading it into the Git repository of the jenkins gear and reference it in the slave configuration like so:


Additionally, you will also need to set a JVM property on the slave to change the location of user.home. This is because Maven will try to create a .m2 directory in user.home by default, but OpenShift applications have no write permissions in that location. Instead, point user home somewhere here:


Configuring the Job(s)

Now everything is ready to configure the actual build job. In case of Jabylon, this is a maven tycho build. I experienced frequent problems on the gear with complex builds, (maven process would terminate unexpectedly with status 137) so I ended up splitting the job in two to reduce the workload on the gear. One builds the modules, the other (triggered  by the first) assembles the eclipse product zip for distribution and archives the resulting zip.

The easiest way to trigger jobs from Github pushs is by installing the Jenkins Github Plugin and activating the respective service hook in github. Now everything should be in place and your application will be build as soon as you push new code to your repository.

Configuring the DIY application

The last step is to configure the DIY application to properly connect it to the OpenShift lifecycle (start, stop, deploy,…). With OpenShift, this is actually super easy. All you need to do is clone the git repository of your DIY application and adjust some shell scripts in .openshift/action_hooks and .openshift/cron. Here’s what I had to do for Jabylon:

deploy script

#delete the old deployment
rm -Rf ${DEPLOY_DIR}
mkdir -p ${DEPLOY_DIR}
#download  and extract the latest product
wget -nv
unzip -q -d ${DEPLOY_DIR}/jabylon

start script

#this is important! You need to bind your application to OPENSHIFT_INTERNAL_IP:OPENSHIFT_INTERNAL_PORT
$JABYLON ${ARGS} start

stop script

./ stop

And last, the cron script to redeploy the application every 24 hours

daily/redeploy script


#first stop the running instance
#deploy the new version from Jenkins
#and start it

Now your demo application should be up and running, gets updated daily and can be started/stopped by command line directly from your workstation.


4 responses to “Jenkins Setup on OpenShift

  1. mendlik October 27, 2012 at 11:17

    This post is a blessing;)
    Right now I’m struggling with a very similar problem.
    Please, could you describe ‘step by step’ how did you create and configure custom ssh slave for jenkins on openshift? (I’m having problems with ssh connection between master-slave)

    • jutzig October 29, 2012 at 22:33

      Hi mendlik,
      I don’t recall doing anything special apart from what I mentioned in the blog already
      -upload the private key to the jenkins gear
      -enter the hostname of the slave gear in the jenkins slave configuration
      -point it to the right private key file
      What problems are you facing?

  2. Martin February 7, 2013 at 14:49

    I can’t find directory .openshift in my Jenkins application, so I can’t find the jenkins startup script to add -D parameter to tell jenkins to use another home directory for maven repo creation. How did you do to overcome that situation?

    • jutzig February 13, 2013 at 21:24

      Hi Martin
      unfortunately it’s been a while that I configured this and eventually I ended up dropping it in favor of build hive, so I don’t remember exact details. However, I’m pretty sure that I’ve set this property directly in jenkins in either the slave configuration, or the job configuration and not in a startup script.
      Hope that helps

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: