Difference between revisions of "Jenkins Setup"

From Officience
Jump to: navigation, search
(Created page with "Coming Soon")
 
 
(16 intermediate revisions by one other user not shown)
Line 1: Line 1:
Coming Soon
+
[[Category: IT Knowledge]]
 +
 
 +
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 copy below script and save as name jenkins_installer.sh.
 +
 
 +
Then upload to /tmp and issue command :
 +
chmod +x jenkins_installer.sh && ./jenkins_installer.sh
 +
 
 +
After installed, we can go to Jenkins panel by domain we entered before os use public ip of jenkins server.
 +
----
 +
<pre>
 +
#!/bin/bash
 +
 
 +
#This script created by quangnhut123 for jenkins automation install on Ubuntu.
 +
#You can feel free to use it and modify to run on specify linux distro.
 +
#Both of non-commercial and commercial can be use.
 +
#Please keep this copyright header for extension use!
 +
 
 +
#Removing some conflict service
 +
apt-get -y remove apache2 php* php5*
 +
 
 +
#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 BLANKED ! ********************"
 +
./jenkins_installer.sh
 +
exit
 +
fi
 +
 
 +
#Install software properties package
 +
apt-get -y install software-properties-common
 +
 
 +
# 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
 +
 
 +
#Add PHP 5.6 source
 +
export LANG=C.UTF-8
 +
add-apt-repository -y ppa:ondrej/php5-5.6
 +
 
 +
#Add Open JDK source
 +
add-apt-repository -y ppa:openjdk-r/ppa
 +
 
 +
# Update the repositories
 +
apt-get -y update
 +
 
 +
#Install JDK
 +
apt-get -y install openjdk-8-jdk
 +
update-alternatives --config java
 +
 
 +
# 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
 +
 
 +
#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
 +
 
 +
#Install and enable services
 +
update-rc.d nginx defaults
 +
service nginx restart
 +
update-rc.d jenkins defaults
 +
service jenkins start
 +
 
 +
#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
 +
 
 +
#Install ANT from repositories
 +
apt-get -y install ant
 +
 
 +
#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
 +
 
 +
#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
 +
 
 +
#Restart service
 +
service nginx restart
 +
</pre>

Latest revision as of 10:31, 13 July 2017


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 copy below script and save as name jenkins_installer.sh.

Then upload to /tmp and issue command : chmod +x jenkins_installer.sh && ./jenkins_installer.sh

After installed, we can go to Jenkins panel by domain we entered before os use public ip of jenkins server.


#!/bin/bash

#This script created by quangnhut123 for jenkins automation install on Ubuntu. 
#You can feel free to use it and modify to run on specify linux distro.
#Both of non-commercial and commercial can be use.
#Please keep this copyright header for extension use!

#Removing some conflict service
apt-get -y remove apache2 php* php5*

#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 BLANKED ! ********************" 
./jenkins_installer.sh
exit
fi

#Install software properties package
apt-get -y install software-properties-common

# 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

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

#Add Open JDK source
add-apt-repository -y ppa:openjdk-r/ppa

# Update the repositories
apt-get -y update

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

# 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

#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

#Install and enable services
update-rc.d nginx defaults
service nginx restart
update-rc.d jenkins defaults
service jenkins start

#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

#Install ANT from repositories
apt-get -y install ant

#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

#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

#Restart service
service nginx restart