Jenkins build server on OpenShift (2) - 22 Jun 2013


I originally wrote on spinning up a Jenkins server for intra-OpenShift deployments with an external repository in Jenkins build server on OpenShift. This post will detail the basic process and major changes that have been required as the OpenShift platform has evolved to the General Availability release.

This assumes you already have an OpenShift account, an application server cartridge, a Jenkins cartridge, and a new diy project created in Jenkins. I would advise against using OpenShift's Jenkins-app-server-integration, and just spin them up separately. At time of writing the OpenShift maintained Jenkins cartridge still reads Jenkins Server 1.4, but it is actually 1.509.1.

create SSH key-pair

Create an SSH key on the fresh Jenkins cartridge in ~/app-root/data/.ssh/id_rsa with ssh-keygen -C jenkins@openshift, and add it to the Account Settings. This will ensure that authentications with the key are accepted on any of your account's cartridges.

deployment to other cartridge from Jenkins

# set deploy user and endpoint
DEPLOY_ENDPOINT=[alpha-num username]@[cart name]-[namespace].rhcloud.com

# Push content to server
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ~/app-root/data/.ssh/id_rsa $WORKSPACE/*.war $DEPLOY_ENDPOINT:~/jbossews/webapps/

# Reload server with new version
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ~/app-root/data/.ssh/id_rsa $DEPLOY_ENDPOINT "~/jbossews/bin/control restart"

As one can see, I am deploying to a JBoss EWS cartridge.

hot deploy

For the JBoss EWS instance to automatically pick up WAR changes and redeploy the context, we have to add in the hot deploy marker file.

  1. Git clone the application's git repo: ssh://[DEPLOY_ENDPOINT]/~/git/[cart name].git
  2. From 6.2. Layout and Deployment Options in the OpenShift Origin Cartridge Guide one removes the source build files: git rm -r src pom.xml
  3. Add the hot deploy marker file: touch .openshift/markers/hot_deploy; git add .openshift/markers/hot_deploy
  4. Commit and push the changes back to the application
  5. SSH into the application and restart everything: ctl_all restart

Your application should be listening for WAR changes, so remove the last line from the shell script in the previous section - ~/jbossews/bin/control restart - as there is no more need to do a full server restart.

service linking

Bitbucket Jenkins service

You can emulate what Bitbucket will do with the following command: wget --auth-no-challenge --post-data="" http://[user]:[API token]@[cart]-[ns].rhcloud.com/job/[project name]/build?token=[token]

http://[user]:[API token]@[cart]-[ns].rhcloud.com/ should be equivalent to what you have in the Endpoint field.

Be sure to configure Jenkins’ Global Security properly so that [user] is able to start builds:

  1. Security Realm: Jenkins's own user database
  2. Authorization: Matrix-based security
    1. Overall: Read
    2. Job: Read, Discover, Build
    3. View: Read

git polling

20130929 EDIT: Seems as though the Bitbucket POST service doesn't want to play ball anymore with my hosted Jenkins instance. Updated the Build Triggers section to Poll SCM every three minutes: */3 * * * *.

468 words. Post tags: Jenkins and OpenShift.

Post content is written by Jason Zerbe and licensed CC BY-NC 3.0.