Jenkins is an open source automation server written in Java that supports continuous integration (CI) and continuous delivery (CD) practices. Nowadays it’s one of the most popular solution between its competitors (TeamCity, Bamboo, CruiseControl, etc..).
The server has an impressive web interface, supports non-Java projects and through plugins the built-in functionality can be conveniently extended. Plugins are vital as they support the integration with several version control systems, databases, build automation software, reporting tools, test frameworks, and general purpose solutions.
Jenkins can be installed as a standalone component or in a servlet container such as Tomcat. The following guide describes how to install Jenkins as a standalone component on Linux Mint/Ubuntu distributions, with some changes or no changes at all installation process might also work in other distributions.
The first step is download the .war release of your preference from the Jenkins official site, I recommend you downloading the LTS (Long-Term Support) Release. Once downloaded place the .war file in a directory of your choice, for instance /opt/jenkins. In my case I have the file in /mnt/data/apps/jenkins as I have all my apps and data mounted in another volume, which is very convenient for me when I have to update or reinstall my Linux distribution.
In the same directory you placed the .war, create a second file named jenkins.sh with the following content. In the script pay attention to the variable “JENKINS_ROOT” as it must point to the directory in which you are placing your files.
### BEGIN INIT INFO # Provides: jenkins # Required-Start: $network # Required-Stop: $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Jenkins CI Server ### END INIT INFO DESC="Jenkins CI Server" NAME=jenkins PIDFILE=/var/run/$NAME.pid RUN_AS=root PATH=/sbin:/bin:/usr/sbin:/usr/bin JENKINS_ROOT=/mnt/data/apps/jenkins export JENKINS_HOME=$JENKINS_ROOT/data start() { start-stop-daemon --start --background --make-pidfile --pidfile $PIDFILE --chuid $RUN_AS --exec /usr/bin/java -- -jar $JENKINS_ROOT/jenkins.war } stop() { start-stop-daemon --stop --pidfile $PIDFILE if [ -e $PIDFILE ] then rm $PIDFILE fi } case $1 in start|stop) $1;; restart) stop; start;; *) echo "Run as $0 "; exit 1;; esac |
Additionally, in the above script, pay attention to the variable “JENKINS_HOME” as it’s redirecting the Jenkins home directory. This directory is the storage location where Jenkins saves all data. By default, home directory is set to ~/.jenkins but you can change the “JENKINS_HOME” variable to point to another location or just comment/delete this line to set the home directory to its default.
$ sudo cp ./jenkins.sh /etc/init.d/jenkins $ sudo chmod 755 /etc/init.d/jenkins $ sudo update-rc.d jenkins defaults |
If everything goes as planned, after restarting your computer Jenkins will be automatically executed during the system initialization without any user intervention or login operation. You can also manage the service state from a console by running the command.
$ service jenkins <stop|start|restart> |
Conclusion
As you can see installing Jenkins as a standalone component using this manual method is a transparent and a simple task. Furthermore, by manually editing the loading script you can customize the location of both Jenkins .war file and the home directory.
Hope you find this guide helpful. If you have any question or suggestion, please don’t hesitate to contact me; I will be willing to answer you.
No comments:
Post a Comment