Difference between revisions of "Jenkins Setup"

From Officience
Jump to: navigation, search
Line 5: Line 5:
  
 
----
 
----
 
+
{{{
 
#!/bin/bash
 
#!/bin/bash
  
Line 148: Line 148:
 
#Restart service
 
#Restart service
 
service nginx restart
 
service nginx restart
 +
}}}

Revision as of 10:06, 8 October 2015

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


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