This post showed how to build GitHub projects with Jenkins, Maven and SonarQube 4 on OpenShift. For starters, it used the Jenkins master node for running build jobs. However, when running on a small gear, the master node might run out of memory pretty fast, resulting in a reboot of the node during builds.
In order to resolve this issue, there are two options:
- limitting the memory of the build or
- running the build on a slave node.
As spawning additional nodes is easy in a PaaS context such as OpenShift and provides a better performance than running builds with small memory, the slave solution seems to be the better approach.
This post shows how.
- Create new DYI app as a slave node (a how-to can be found here), name the node e.g.
slave
- Create node in Jenkins
- Go to Jenkins web UI and create new node:
https://jenkins-.rhcloud.com/computer/new
- Set the following values:
Remote FS root:/app-root/data
folder on slave. Typically this is/var/lib/openshift//app-root/data/jenkins
, you can find out by SSHing to the slave node and callingecho $OPENSHIFT_DATA_DIR/app-root/data/jenkins
Labels:
Some label to use within builds to refer the node, e.g.OS Slave #1
Host:
the slave’s hostname, e.g.slave-.rhcloud.com
- Add Credentials
username
:
Private Key File:
Path to a private key file that is authorized for your OpenShift account. In the <a href="https://itaffinity.wordpress.com/2015/02/26/building-github-projects-with-jenkins-maven-and-sonarqube-4-1-1-on-openshift/”>first post this path was used:/var/lib/openshift//app-root/data/git-ssh/id_rsa
. Note:$OPENSHIFT_DATA_DIR
seems not to work here.
BTW: You can change the credentials any time later via this URLhttps://jenkins-.rhcloud.com/credentials/
- Go to Jenkins web UI and create new node:
- Prepare slave node: Create same environment as on master in the <a href="https://itaffinity.wordpress.com/2015/02/26/building-github-projects-with-jenkins-maven-and-sonarqube-4-1-1-on-openshift/”>first post
- Create folder structure
mkdir $OPENSHIFT_DATA_DIR/jenkins mkdir $OPENSHIFT_DATA_DIR/.m2 echo -e "<settings><localRepository>$OPENSHIFT_DATA_DIR/.m2</localRepository></settings>" > $OPENSHIFT_DATA_DIR/.m2/settings.xml
- Copy SSH directory from master to same directory on slave, e.g.
scp -rp -i $OPENSHIFT_DATA_DIR/.ssh $OPENSHIFT_DATA_DIR/.ssh <slave's UID>@slave-<your account>.rhcloud.com:app-root/data/.ssh
- As the different cartridges (jenkins and DIY) have different environment variables for their local IP addresses (
$OPENSHIFT_JENKINS_IP
vs$OPENSHIFT_DIY_IP
) we’ll have to improvise at this point. There are two options: Either- Replace all occurrences of
$OPENSHIFT_JENKINS_IP
In all builds and inhttps://jenkins-.rhcloud.com/configure
Sonar
|Sonar installations
Database URL:
jdbc:postgresql://$OPENSHIFT_DIY_IP:15555/sonarqube
or - Create an
$OPENSHIFT_JENKINS_IP
environment variable on your slave machinerhc env set OPENSHIFT_JENKINS_IP=<value of ย $OPENSHIFT_DIY_IP> -a slave
You can find out the value of $OPENSHIFT_DIY_IP by SSHing to the slave and execute
echo $OPENSHIFT_DIY_IP
- I’d love to hear suggesstions that do better ๐
- Replace all occurrences of
- Create folder structure
- Adapt Build
Easiest way is to not use the master at all.
To do so, go tohttps://jenkins-.rhcloud.com/configure
and set
# of executors
to0
.
HitApply
- Limit memory usage.
Make sure the slave does not run out of memory (which leads to a restart of the node):
Global properties
|Environment variables
name:
MAVEN_OPTS
value:
-Xmx512m
HitSave
. - Now run a build. It should run on the slave and hopefully succeed ๐
See also Libor Krzyzanek’s Blog: Jenkins on Openshift wi… | JBoss Developer
Thanks for sharing the post.
I faced the following error:
http://stackoverflow.com/questions/31341920/unable-to-git-clone-from-openshift-jenkins-static-slave
May I know you come across the error and have any idea on the solution?
I commented on the question a while ago. Did you have a chance to try the proposed solution?