Jenkins Setup

From Officience
Revision as of 10:07, 8 October 2015 by Quang Nhut (talk | contribs)
Jump to: navigation, search

Jenkins CI is the leading open-source continuous integration server. Built with Java, it provides 985 plugins to support building and testing virtually any project.

Today, I want to share a small script can install and configure Jenkins automatically. Do it very simple by issues 3 command : chmod +x jenkins_installer.sh && ./jenkins_installer.sh


  1. !/bin/bash
  1. This script created by quangnhut123 for jenkins automation install on Ubuntu.
  2. You can feel free to use it and modify to run on specify linux distro.
  3. Both of non-commercial and commercial can be use.
  4. Please keep this copyright header for extension use!
  1. Removing some conflict service

apt-get -y remove apache2 php* php5*

  1. Update system for newest package index

apt-get -y update && apt-get -y upgrade apt-get -y install curl

echo -n "Enter Your Jenkins Domain : " read jenkinsdomain svip=`curl -ss http://ipecho.net/plain` if [ "$jenkinsdomain" = "" ]; then clear

   echo -e "******************** YOUR DOMAIN CAN NOT BE BLANK ! ********************" 

./jenkins_installer.sh exit fi

  1. Install software properties package
  2. apt-get -y remove python-software-properties
  3. apt-get -y autoremove

apt-get -y install software-properties-common

  1. Add Jenkins source

wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | apt-key add - echo 'deb http://pkg.jenkins-ci.org/debian binary/' >> /etc/apt/sources.list

  1. Add PHP 5.6 source

export LANG=C.UTF-8 add-apt-repository -y ppa:ondrej/php5-5.6

  1. Add Open JDK source

add-apt-repository -y ppa:openjdk-r/ppa

  1. Update the repositories

apt-get -y update

  1. Install JDK

apt-get -y install openjdk-8-jdk update-alternatives --config java

  1. echo "JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"" > /etc/environment
  2. source /etc/environment
  1. Install Jenkins, Nginx, Git, PHP 5.6 (latest) and Xdebug (for code coverage) and other tools

apt-get -y install jenkins nginx git zip unzip bzip2 php5-cli php5-fpm php5-xdebug php5-xsl php5-dev

  1. Config nginx as forward proxy for jenkins

mv /etc/nginx/sites-enabled/default /etc/nginx/sites-enabled/default.bak special="$" host="host" host="$special$host" remote="remote_addr" remote="$special$remote" proxy="proxy_add_x_forwarded_for" proxy="$special$proxy"

cat > "/etc/nginx/sites-enabled/default" <<END server {

 listen 80;
 server_name $svip $jenkinsdomain;
 location / {
   proxy_pass              http://localhost:8080;
   proxy_set_header        Host $host;
   proxy_set_header        X-Real-IP $remote;
   proxy_set_header        X-Forwarded-For $proxy;
   proxy_connect_timeout   150;
   proxy_send_timeout      100;
   proxy_read_timeout      100;
   proxy_buffers           4 32k;
   client_max_body_size    8m;
   client_body_buffer_size 128k;
 }

} END

  1. Install and enable services
  2. systemctl enable nginx.service

update-rc.d nginx defaults

  1. systemctl start nginx.service

service nginx restart

  1. systemctl enable jenkins.service

update-rc.d jenkins defaults

  1. systemctl start jenkins.service

service jenkins start

  1. Install debug tools

wget https://phar.phpunit.de/phpunit.phar chmod +x phpunit.phar mv phpunit.phar /usr/local/bin/phpunit wget https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar chmod +x phpcs.phar mv phpcs.phar /usr/local/bin/phpcs wget https://phar.phpunit.de/phploc.phar chmod +x phploc.phar mv phploc.phar /usr/local/bin/phploc wget http://static.pdepend.org/php/latest/pdepend.phar chmod +x pdepend.phar mv pdepend.phar /usr/local/bin/pdepend wget http://static.phpmd.org/php/latest/phpmd.phar chmod +x phpmd.phar mv phpmd.phar /usr/local/bin/phpmd wget https://phar.phpunit.de/phpcpd.phar chmod +x phpcpd.phar mv phpcpd.phar /usr/local/bin/phpcpd wget http://phpdox.de/releases/phpdox.phar chmod +x phpdox.phar mv phpdox.phar /usr/local/bin/phpdox

  1. Install ANT from repositories

apt-get -y install ant

  1. Install php-template for jenkins

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/ echo "Waitting for Jenkins starting completed..." sleep 15 cd ~ wget http://localhost:8080/jnlpJars/jenkins-cli.jar java -jar jenkins-cli.jar -s http://localhost:8080 reload-configuration

  1. Install and Update Jenkins Plugins

UPDATE_LIST=$(java -jar /root/jenkins-cli.jar -s http://localhost:8080/ list-plugins | grep -e ')$' | awk '{ print $1 }' ); if [ ! -z "${UPDATE_LIST}" ]; then

   echo Updating Jenkins Plugins: ${UPDATE_LIST}; 
   java -jar jenkins-cli.jar -s http://localhost:8080/ install-plugin ${UPDATE_LIST};    

fi java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin github checkstyle cloverphp crap4j dry htmlpublisher jdepend plot pmd violations warnings xunit java -jar jenkins-cli.jar -s http://localhost:8080 safe-restart

  1. Restart service

service nginx restart