You are on page 1of 21

CICD-Flow

Continuous Integration?

As soon as Developer push the code , the CI system(Jenkins) get the code from GIT.

It will run the unit test cases using maven. Then it will build,

create the package and execute SonarQube report and

it will upload the artifact into artifact repository and

will send the email notification to Developer, weather build is Success or fail.

Then Developer fix it and push the code to GIT.

CI Benefits: Immediate Bug fixing


Jenkins Installation Process:
The prerequisite is Java, so first install Java
1 cd /opt/

2 yum install wget -y

3 wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie"


http://download.oracle.com/otn-pub/java/jdk/8u131-
b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.rpm

4 yum install jdk-8u131-linux-x64.rpm -y

5 java –version

Now install Jenkins


6 wget https://get.jenkins.io/redhat-stable/jenkins-2.332.1-1.1.noarch.rpm

7 yum install jenkins-2.332.1-1.1.noarch.rpm -y

8 systemctl enable jenkins

9 systemctl start jenkins

10 systemctl status Jenkins


Install the GIT in Linux server where Jenkins is installed.
Configure the New job

Give the Job name, select pipeline project type and then click on OK

Step1) Get the code from GitHub


Step2) Configure maven and build to get the war file
War file is generated

“maven3.6.2”

/var/lib/Jenkins in the Jenkins home directory we see /tools directory here we will see maven3.6.2

‘maven3.6.2’ tool name will assign, the above path to variable ‘maven’

Install Tomcat
The prerequisite is Java, so first install Java
1 cd /opt/

2 yum install wget -y

wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie"


http://download.oracle.com/otn-pub/java/jdk/8u131-
b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.rpm

4 yum install jdk-8u131-linux-x64.rpm -y

5 java –version

Now install Tomcat


wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.65/bin/apache-tomcat-9.0.65.zip

ls

unzip apache-tomcat-9.0.65.zip

cd apache-tomcat-9.0.65

ls

cd bin/

In bin directory we find startup.sh and catalina.sh files, these files are useful to start the tomcat
server.

Give execute permissions to all the shell script (sh) files

chmod u+x *.sh

Create soft link to the startup.sh file

ln -s /opt/apache-tomcat-9.0.65/bin/startup.sh /usr/bin/startTomcat

ln -s /opt/apache-tomcat-9.0.65/bin/shutdown.sh /usr/bin/stopTomcat

Now from opt directory itself can start the Tomcat

Cd /opt/
Starttomcat

Tomcat is started

Open the port 8080

Now we can access the Tomcat server

Now update context.xml file which is in the webapps directory


To access this need to create user in ‘tomcat-users.xml’ file, which is in the ‘conf’ directory
Create user, password, roles

Restart the tomcat server


Now we can access tomcat application server ,manager

Now deploy the application to tomcat server

Deploy is nothing but keeping the war file into Webapps directory

To copy file from one server to another server we use scp command.

Need to create SSH agent token for providing Tomcat credentials to Jenkins.

For this first Install SSH agent plugin


Give write access to webapps directory
stage('DeployapplicationtoTomcat'){

steps{

sshagent(['61cf36c3-649c-461a-bd1c-ac157c21c2a6']) {

sh "scp -o StrictHostKeyChecking=no target/maven-web-application.war ec2-


user@65.2.81.26:/opt/apache-tomcat-9.0.65/webapps"

Now we find the application in Tomcat server

To trigger the build automatically when there is updated code in the GitHub
Pool Scm→30min →ongoing development→every 30min Jenkins will check in Github ,is there any
updated code or not(commit Id is diff),build is going to trigger.

Build periodically→ selenium test cases→need to run everyday night 12am→what ever timeintervel
you have configured it will trigger, irrespective of updated code.

GitHub webhook→instead Jenkins go and check, Github will inform if there is updated code,and
Github will trigger the Job.

To make Github to trigger the Job

In Jenkins configure the job

In the GitHub goto repository and click on settings Tab, and add the webhook
As payload url give the jekins url and give the context path as ‘github-webhook’

Content type : application/json

Which events would you like to trigger this webhook?

Just the push event.

If you got green tick mark ,mean webhook is configured successfully.


Edit the content in home.jsp file and save the changes.

Immediately build has triggered in Jenkins automatically.

You can see in console output ,the Job was triggered by ‘Github push’

You might also like