-
Notifications
You must be signed in to change notification settings - Fork 1
Jenkins server
Jenkins is an award-winning application that monitors executions of repeated jobs, such as building a software project or jobs run by cron. Among those things, current Jenkins focuses on the following two jobs:
- Building/testing software projects continuously, just like CruiseControl or DamageControl. In a nutshell, Jenkins provides an easy-to-use so-called continuous integration system, making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. The automated, continuous build increases the productivity.
- Monitoring executions of externally-run jobs, such as cron jobs and procmail jobs, even those that are run on a remote machine. For example, with cron, all you receive is regular e-mails that capture the output, and it is up to you to look at them diligently and notice when it broke. Jenkins keeps those outputs and makes it easy for you to notice when something is wrong.
Follow instructions for setting up Jenkins for redhat distributions. This will install the server with default configuration.
- Creates a
jenkins
user andjenkins
group - You might need to do a
chown root:jenkins
on SSL certificates that Jenkins needs for https - Jenkins' home dir is
/var/lib/jenkins
. This is where everything Jenkins lives. - Logs are stored in
/var/log/jenkins
- Log auto-rotation is set up in
/etc/logrotate.d/jenkins
- You can start/stop jenkins via
service
commands - By default, the installation set jenkins to autostart at level 3 and 5
- To disable Jenkins auto start, you can do:
chkconfig jenkins off
By default, Jenkins is set up for open access at port 8080. To begin securing your server, change the default port and enable https. You will have to modify the /etc/sysconfig/jenkins
configuration file. It's a good idea to familiarize yourself with the available Jenkins command line parameters and update the config with the following values:
# Set to -1 to disable the http port
JENKINS_PORT="-1"
# This sets Jenkins to listen to https://<server>:8998
# Then points to your https certificate and private key
JENKINS_ARGS="--httpPort=-1 --httpsPort=8998 --httpsCertificate=/etc/pki/tls/certs/m2_ccle_ucla_edu_cert.cer --ht
tpsPrivateKey=/etc/pki/tls/private/m2_ccle_ucla_edu-san_private.key"
Note: make sure the public cert and private key files are read-able by the "jenkins" user. Jenkins service will fail to start if this is not set.
Once you have your config set up, start the server with service jenkins start
and go to your secure https site at your designated port. Go to your Jenkins dashboard and click on Configure Jenkins > Set up global security
to enable access restrictions. It's possible to set up many schemes, but we chose to have Jenkins manage its own user database. See the standard security setup page to view all possible options. Follow the directions given to use Jenkins' own database with Matrix based security
.
If your server is not starting up, check the logs in /var/log/jenkins
. It's possible Jenkins might not be finding your certificates or it's unable to open them due to permissions.
Jenkins comes with some pre-installed plugins by default, so check if you already have these available, otherwise install:
- Git plugin
- GitHub plugin
- PHPUnit (xUnit)
- Clover coverage
- Code checker
All Jenkins jobs are run within the context of the jenkins
user, so this user needs to have a Github key in order to pull the git project. Follow the Github tutorial on generating ssh keys, but do so in the context of the jenkins
user. Once your keys are generated and you've verified that jenkins
has access to Github, you're ready to go!
@todo
To run Behat tests that require Selenium, need to install Xvfb virtual frame buffer so that we can run the Selenium server in a headless mode. In Redhat, Xvfb can be installed with the xorg-x11-server-Xvfb.x86_64
package.
To run the selenium server standalone jar with the frame buffer:
DISPLAY=:1 xvfb-run java -jar selenium-server-standalone-2.33.0.jar
This will display the selenium server output which is generally unreadable, but it might be worthwhile for debugging purposes. To exit the process do Ctrl + C
. That single command is good for party tricks, but we want to give Jenkins more control so that it can start and stop the selenium server.
We want to run selenium as a service that Jenkins can start and stop. To do this we need to create a system V init script. The following script assumes that there exists a /var/lib/jenkins/selenium
folder with the selenium-server-standalone-2.33.0.jar
file. It's also set up so that only the jenkins
user can start and stop it.
#!/bin/bash
#
# chkconfig: 35 90 12
# description: Selenium server as a service
#
# Get function from functions library
. /etc/init.d/functions
selenium="/var/lib/jenkins/selenium"
lockfile="$selenium/.lock/selenium-server"
logfile="$selenium/log/out.log"
# Check jenkins user
jenkinscheck() {
if [ "$(id -un)" != "jenkins" ]; then
echo "This script must be run as jenkins user" 1>&2
exit 1
fi
}
# Start the service selenium-server
start() {
jenkinscheck
echo -n $"Starting Selenium server"
Xvfb :99 -ac > /dev/null &
export DISPLAY=:99
java -jar $selenium/selenium-server-standalone-2.33.0.jar -log $logfile &
### Create the lock file ###
touch $lockfile
success $"Selenium server startup"
echo
}
# Restart the service selenium-server
stop() {
jenkinscheck
echo -n $"Stopping Selenium server "
killproc Xvfb
killproc java
### Now, delete the lock file ###
rm -f $lockfile
echo
}
### main logic ###
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status selenium-server
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
This script will let Jenkins start the headless selenium server with service selenium start
and stop it with service selenium stop
. For this to work, this script needs to exist in /etc/init.d/selenium
.
Reference:
- http://www.alittlemadness.com/2008/03/05/running-selenium-headless/
- http://stackoverflow.com/questions/6183276/how-do-i-run-selenium-in-xvfb
- http://coreygoldberg.blogspot.com/2011/06/python-headless-selenium-webdriver.html
- http://corpocrat.com/2008/08/19/how-to-install-xvfb-x11-server-in-linux-server/