i) Jenkins is a tool that is used for
automation, and it is an open-source tool.
ii) Jenkins allows all the developers to build, test and
deploy software.
iii) Jenkins tool written in Java programming language.
iv) Jenkins we can make a continuous
integration and continuous delivery (CI/CD) of projects or end-to-endpoint
automation.
2. How to install the Jenkins and which tools will be required for Jenkins install.
Step 1: install java
on linux.
1.We will be using open java for our demo, Get the latest
version from http://openjdk.java.net/install/
2.yum install java-1.8 java-1.8.0-openjdk-devel
3.Confirm Java Version and set the java home
4.java -version
5.find /usr/lib/jvm/java-1.8* | head -n 3
6.JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-<Java version
which seen in the above output>
7.export JAVA_HOME
8.PATH=$PATH:$JAVA_HOME
9.To set it permanently update your .bash_profile
# vi ~/.bash_profile
The output should be something like this,
[root@~]# java -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
Step 2: Jenkins
Repository
# wget -O /etc/yum.repos.d/jenkins.repo http://jenkins-ci.org/redhat/jenkins.repo
# rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
Step 3: Install
Jenkins
# yum install Jenkins
Step 4: Start Jenkins
# /etc/init.d/jenkins start | stop | restart
# chkconfig jenkins on
Step 5: Verify
Jenkins
# netstat -ntulp | grep 8080
# vim /etc/sysconfig/Jenkins
Default:
JENKINS_PORT="8080"
New:
JENKINS_PORT="8443"
Step 6: Access the
Jenkins Web portal
Access the URL : http://<Ip-Address-of-your-Server>:8080
Admin password is
created and stored in the log file “/var/log/jenkins/jenkins.log“.
Run the below command to get the password.
[root@jenkins ~]# grep -A 5 password
/var/log/jenkins/jenkins.log
Copy the password and paste it in above windows and click on
Continue..
In the next windows Select the option : Install suggested plugins
As we can see
required plugin installation is in progress for Jenkins. Once it is done with
plugin installation. It will ask to create Admin User
Click on Save and Finish
click on “Start using Jenkins”
Jenkins user login :-
Go to :- Manage Jenkins à Configure Global Security
Uncheck “Allow users
to sign up”
User:-admin, password:-admin
How to Create Jobs
for Projects :-
Click “New Item”
Type :- Jobs Name à Freestyle Project à OK
Specify the Project Description
SVN Structure:-
SVN Repo :- http://192.168.1.21:81/svn/repo_data
Three working Directory in Repo :-
SVN :- http://192.168.1.21:81/svn/repo_data/Project_name/{Trunk,Tag,Branch}
Code URL :- http://192.168.1.21:81/svn/repo_data/newsybytes/trunk/<code>newsybytes
# visudo
jenkins ALL=NOPASSWD:/bin/chown , /bin/chmod , /usr/bin/rsync , /bin/cp
Global Variable Set :-
Manage Jenkins à configure system à Global properties
Deployment Script :-
# vim /var/lib/Jenkins/test.sh
#!/bin/bash
date1=$(date +%d-%m-%Y-%T)
code_path="$WORKSPACE/$Deployment_name"
revision_no=$(svn info --username admin --password admin
$SVN_URL --no-auth-cache | grep "Last Changed Rev:" | cut -d
":" -f2 | cut -d " " -f2)
last_commet=$(svn log -l 1 --username admin --password admin
$SVN_URL --no-auth-cache)
echo "################# START BUILD
######################"
mkfile=$(touch
/tmp/revision_$Deployment_name)
Rev_number=$(cat /tmp/revision_$Deployment_name)
old_rev_no=$(echo
"$Rev_number")
if [[ "$old_rev_no" == "$revision_no"
]];then
echo -e
"LAST SVN REVISION NO:- $revision_no\n"
echo
"LAST COMMIT :-"
echo -e
"$last_commet\n"
echo -e
"NO ANY UPDATE....!\n"
else
delete_svn=$(find
$code_path -name ".svn" -type d -exec rm -rf "{}" \; 2>
/dev/null)
rc=$(sudo rsync -a --delete $code_path/$Deployment_name/
/var/www/html/$Deployment_name/)
per=$(sudo
chmod -R 777 /var/www/html/$Deployment_name)
own=$(sudo
chown -R root:root /var/www/html/$Deployment_name)
echo
"LAST COMMIT :-"
echo -e
"$last_commet\n"
echo -e
"PERVIOUS SVN REVISION NO:- $old_rev_no\n"
echo -e
"CURRENT SVN REVISION NO:- $revision_no\n"
echo -e
"DEPLOYMENT IS COMPLETED..\n"
svn_no=$(echo
"$revision_no" > /tmp/revision_$Deployment_name)
fi
echo "################# COMPLETED BUILD
#####################"
#chmod -R 777 /var/lib/Jenkins/test.sh
Mailing
Configuration:-
Manage Jenkins à
configure System à Extended E-mail Notification
Manage Jenkins à
configure System à E-mail Notification
Post-build Actions
Triggers à add Trigger à Always
Add à Recipient List,
Developers
Apply à
Save
Need to multiple parameter
plugin name :- active choices
1.General à
select This project is parameterized àActive
Choices Parameter
Name:- Env
Select :- Groovy script
return[
'',
'Production',
'Development',
'Test',
'Stage'
]
Fallback Script
Groovy Script ->
return['error']
Description->
Please select an Environment
Choice Type -> Single Select
Filter starts at -> 1
Add à Active Choices Reactive Parameter
Name -> Servers
Select Groovy Script à
if (Env.equals("Production")) {
return ["Prod01", "Prod02",
"Prod03", "Prod04"]
} else if (Env.equals("Development")) {
return ["Dev01", "Dev02",
"Dev03"]
} else if (Env.equals("Test")) {
return ["test01", "test02"]
} else {
return ["Unknown state"]
}
Fallback Script
Groovy Script ->
return ['script Error']
Choice Type -> Single Select
Referenced parameters -> Env
Filter starts at -> 1
Build :-
echo "$Env"
echo "$Servers"
No comments:
Post a Comment