Setting up a Php Continuous integration environment in Centos 6

As part of my job I need to create a continuous integration environment for my develops in Php.

first I installed Gitlab and then I installed Jenkins using the web page tutorial ( http://jenkins-ci.org/ ).

you need to have enabled EPEL repos http://fedoraproject.org/wiki/EPEL and rpm Fusion repos聽http://rpmfusion.org/ .

when you have Jenkins installed you will need install the needed packages open a root terminal and write:

yum install ant php php-phpunit-phploc php-pdepend-PHP-Depend.noarch php-phpmd-PHP-PMD.noarch php-phpunit-phpcpd.noarch php-phpunit-phploc.noarch php-pear-PHP-CodeSniffer.noarch php-phpunit-PHP-CodeBrowser.noarch

The next step is add the php template into Jenkins CI

  • cd /var/lib/jenkins/jobs
  • mkdir php-template
  • cd php-template
  • wget https://raw.github.com/sebastianbergmann/php-jenkins-template/master/config.xml
  • cd ..
  • chown -R jenkins:jenkins php-template/
  • /etc/init.d/jenkins restart

now we can create a new php project based on the php-template 馃檪

Jenkins Xvfb in Centos 6

During my last adventures with Jenkins y suffered into a new problem trying to running my gtester’s test battery.

 [exec] TEST: tests/stkmngtest... (pid=13754)
     [exec]
     [exec] Gtk-WARNING **: cannot open display:
     [exec] aborting...
     [exec] FAIL: tests/stkmngtest

that makes my test suite were aborted聽 and also makes Jenkins useless, and useless things are my competitors because the only useless thing allowed at home is me 馃槢 .

The basic problem is that there no are a XOrg session running, first I change runlevel to 5 and expect see test runing聽 a big FAIL was the result.

after reading a bit of literature I discover a thing called Xvfb

for install follow these steps

su

yum install Xvfb

yum install mesa-dri-drivers

the next step was try to install Xvfb plugin in jenkins but i doesn’t work it give these exception

FATAL: null
java.lang.NullPointerException
	at org.jenkinsci.plugins.xvfb.XvfbBuildWrapper.decorateLauncher(XvfbBuildWrapper.java:165)
	at hudson.model.AbstractBuild$AbstractRunner.createLauncher(AbstractBuild.java:525)
	at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:452)
	at hudson.model.Run.run(Run.java:1434)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
	at hudson.model.ResourceController.execute(ResourceController.java:88)
	at hudson.model.Executor.run(Executor.java:239)

I found a quick and dirty solution that is put a xvfb-run call in commands that need a xserver like this

<target name=”runtest” description=”run glib test”>
<exec executable=”xvfb-run”>
<arg value=”gtester”/>
<arg value=”tests/stkmngtest”/>
<arg value=”–keep-going”/>
<arg value=”-o=Tests.xml”/>
</exec>
</target>

the solution for solve these problem is configure Jenkins plugin BIG BIG BIG THANKS TO Tomasz Wysocki, he show me the missing configuration options.

Here for global settings

And here for project settings

Jenkins git ssh auth in Centos 6

jenkins

After install Gitlab the next step聽 was install Jenkins and start to work with a continuous integration server. I installed Jenkins following doc and create a new project for one of my repos. and i get this output

Building in workspace /var/lib/jenkins/jobs/PFC/workspace
Checkout:workspace / /var/lib/jenkins/jobs/PFC/workspace – hudson.remoting.LocalChannel@1aba936a
Using strategy: Default
Cloning the remote Git repository
Cloning repository origin
ERROR: Error cloning remote repo ‘origin’ : Could not clone gitolite@git.luzem.com:pfc.git
hudson.plugins.git.GitException: Could not clone gitolite@git.luzem.com:pfc.git
at hudson.plugins.git.GitAPI.clone(GitAPI.java:245)
at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1117)
at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1059)
at hudson.FilePath.act(FilePath.java:832)
at hudson.FilePath.act(FilePath.java:814)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1059)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1218)
at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:581)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:470)
at hudson.model.Run.run(Run.java:1421)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:238)
Caused by: hudson.plugins.git.GitException: Command “git clone –progress -o origin gitolite@git.luzem.com:pfc.git /var/lib/jenkins/jobs/PFC/workspace” returned status code 128:
stdout: Initialized empty Git repository in /var/lib/jenkins/jobs/PFC/workspace/.git/

stderr: Host key verification failed.
fatal: The remote end hung up unexpectedly

at hudson.plugins.git.GitAPI.launchCommandIn(GitAPI.java:779)
at hudson.plugins.git.GitAPI.access$000(GitAPI.java:38)
at hudson.plugins.git.GitAPI$1.invoke(GitAPI.java:241)
at hudson.plugins.git.GitAPI$1.invoke(GitAPI.java:221)
at hudson.FilePath.act(FilePath.java:832)
at hudson.FilePath.act(FilePath.java:814)
at hudson.plugins.git.GitAPI.clone(GitAPI.java:221)
… 12 more
Trying next repository
ERROR: Could not clone repository
FATAL: Could not clone
hudson.plugins.git.GitException: Could not clone
at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1129)
at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1059)
at hudson.FilePath.act(FilePath.java:832)
at hudson.FilePath.act(FilePath.java:814)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1059)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1218)
at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:581)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:470)
at hudson.model.Run.run(Run.java:1421)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:238)

When you install Jenkins from the repos one problem is configure ssh keys for jenkins user, the first thing to configure ssh keys was su jenkins and run ssh keygen but it failed because i can’t log with Jenkins user.

i open a terminal as root on server machine as root and start writing:

vim /etc/passwd

changing jenkins line

jenkins:x:492:486:Jenkins Continuous Build server:/var/lib/jenkins:/bin/false

for

jenkins:x:492:486:Jenkins Continuous Build server:/var/lib/jenkins:/bin/bash

after changuing this line you can do

su jenkins

cd

ssh-keygen

cat .ssh/id_rsa.pub

now you have the key for your jenkins user and it can pull from your repos

for more security edit again /etc/passwd and pul false in jenkins shell

jenkins:x:492:486:Jenkins Continuous Build server:/var/lib/jenkins:/bin/false