Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Extending Jenkins

You're reading from   Extending Jenkins Get a complete walkthrough of the many interfaces available in Jenkins with the help of real-world examples to take you to the next level with Jenkins

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher
ISBN-13 9781785284243
Length 152 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Donald Simpson Donald Simpson
Author Profile Icon Donald Simpson
Donald Simpson
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Preparatory Steps FREE CHAPTER 2. Automating the Jenkins UI 3. Jenkins and the IDE 4. The API and the CLI 5. Extension Points 6. Developing Your Own Jenkins Plugin 7. Extending Jenkins Plugins 8. Testing and Debugging Jenkins Plugins 9. Putting Things Together Index

Extending the basic setup

When you exit from the command prompt or shell that started the process that we looked at previously, the Jenkins instance will stop with the exit, so for anything beyond a very quick ad hoc test, some form of initialization or process management script is highly recommended. Such a script can also be easily tailored to perform a few "nice to have" functions for you, for example, things such as these:

  • Starting up at system boot time
  • Catering to stop|start|restart|status requests
  • Redirecting console output to a log file so that you can monitor it for issues
  • Running as a background/daemon process
  • Running on a nonstandard port by setting the --httpPort= parameter, in cases where port 8080 is already used by another application
  • Binding to a specific network interface, rather than the default 0.0.0.0 value using the --httpListenAddress= option

This Ubuntu-based example script from the home page demonstrates many of the previously mentioned features of Jenkins that is running under Tomcat. The script can be found at https://wiki.jenkins-ci.org/display/JENKINS/JenkinsLinuxStartupScript and is as follows:

#!/bin/sh
#
# Startup script for the Jenkins Continuous Integration server
# (via Jakarta Tomcat Java Servlets and JSP server)
#
# chkconfig: - 85 15
# description: Jakarta Tomcat Java Servlets and JSP server
# processname: jenkins
# pidfile: /home/jenkins/jenkins-tomcat.pid

# Set Tomcat environment.
JENKINS_USER=jenkins
LOCKFILE=/var/lock/jenkins
export PATH=/usr/local/bin:$PATH
export HOME=/home/jenkins
export JAVA_HOME=/usr/lib/jvm/java-6-sun
export JENKINS_BASEDIR=/home/jenkins
export TOMCAT_HOME=$JENKINS_BASEDIR/apache-tomcat-6.0.18
export CATALINA_PID=$JENKINS_BASEDIR/jenkins-tomcat.pid
export CATALINA_OPTS="-DJENKINS_HOME=$JENKINS_BASEDIR/jenkins-home -Xmx512m -Djava.awt.headless=true"

# Source function library.
. /etc/rc.d/init.d/functions

[ -f $TOMCAT_HOME/bin/catalina.sh ] || exit 0

export PATH=$PATH:/usr/bin:/usr/local/bin

# See how we were called.
case "$1" in
  start)
        # Start daemon.
        echo -n "Starting Tomcat: "
        su -p -s /bin/sh $JENKINS_USER -c "$TOMCAT_HOME/bin/catalina.sh start"
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch $LOCKFILE
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down Tomcat: "
        su -p -s /bin/sh $JENKINS_USER -c "$TOMCAT_HOME/bin/catalina.sh stop"
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f $LOCKFILE
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  condrestart)
       [ -e $LOCKFILE ] && $0 restart
       ;;
  status)
        status -p $CATALINA_PID -l $(basename $LOCKFILE) jenkins
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
esac
exit 0

Note that the http://jenkins-ci.org/ home page also hosts Native Installers for many popular operating systems under the Native packages column. These pages provide download links and installation instructions for each OS.

You may want to look at running Jenkins in a J2EE container too, which can often lead to a more seamless fit with your existing software stack and architecture. This may mean that you will inherit additional benefits, such as the container's logging, authentication, authorization, or resilience. Jenkins can be run with many popular J2EE compatible containers, including the following:

  • WebSphere
  • WebLogic
  • Tomcat
  • JBoss
  • Jetty
  • Jonas

There are more init script examples and detailed installation instructions readily available on the Web, which should cover any combination of operating system and container setup. The point of this is that you should be able to set up Jenkins to suit your environment and preferences.

For the purposes of this book, we will assume that Jenkins is being run directly from the command line on the local host. If you are using a J2EE container to host the application or running the application on a remote host, the only difference you will notice is that you may need to perform additional admin and deployment steps.

You have been reading a chapter from
Extending Jenkins
Published in: Dec 2015
Publisher:
ISBN-13: 9781785284243
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image