You are on page 1of 80

Learn & Build

Final Project

CI PIPELINE PROJECT
USING JENKINS AND GITHUB

Submitted To :- Aashish Mittal Sir Submitted By :- Vibhanshu Kumar Shubham


Introduction

CI/CD (continuous integration)/ (continuous delivery) pipeline in devops is an automated


workflow that enables teams to continuously integrate code changes, run tests, and deploy
software to production or staging environments. This approach helps improve the speed,
reliability, and quality of software development and delivery by automating repetitive tasks
and ensuring that code changes are thoroughly tested before reaching users.
Ci/cd is a fundamental concept in devops, a set of practices that aim to streamline and
automate the software development and delivery process. CI/CD pipelines are a key component
of this approach.
Ci is the practice of integrating code changes into a shared repository frequently while cd is the
practice of ensuring that code changes are always in a deployable state.
The key goals of continuous integration are to find and address bugs quicker, make the process
of integrating code across a team of developers easier, improve software quality and reduce
the time it takes to release new feature updates. Some popular CI tools are jenkins, teamcity,
and bamboo.
Continuous delivery automates the entire software release process. The final decision to deploy
to a live production environment can be triggered by the developer/project lead as required.
Some popular CD tools are AWS code deploy, jenkins, and gitlab.
Ci/ cd enables organizations to develop software quickly and efficiently. CI/CD enables an
effective process for getting products and software to market faster than ever before,
continuously moving code into production, and ensuring a steady flow of new features
A CI/CD pipeline is a software development practice that automates the process of software
delivery. It involves a series of steps that include building, testing, and deploying code changes
automatically.
Continuous integration (ci) and continuous delivery (cd) are two key concepts in the ci/c
In SDLC, Ci Mainly Covers The Source And Build Phases. A CI Pipeline Typically Involves These Steps:
• DETECT CHANGES IN THE CODE
• ANALYZE THE QUALITY OF THE SOURCE CODE
• BUILD
• EXECUTE ALL UNIT TESTS
• EXECUTE DEPLOYABLE ARTIFACTS
• REPORT STATUS
If any of the above steps fail, the integration stops immediately, and the team is notified about the
result.
JENKINS

• JENKINS IS AN OPEN-SOURCE AUTOMATION SERVER THAT ALLOWS DEVELOPERS TO BUILD,


TEST, AND DEPLOY SOFTWARE.
• IT IS WRITTEN IN JAVA AND CAN BE USED FOR CONTINUOUS INTEGRATION OF PROJECTS
OR END-TO-END AUTOMATION.
• JENKINS PROVIDES HUNDREDS OF PLUGINS TO SUPPORT BUILDING, DEPLOYING, AND
AUTOMATING ANY PROJECT.
• IT IS A SELF-CONTAINED JAVA-BASED PROGRAM THAT CAN RUN ON VARIOUS OPERATING
SYSTEMS SUCH AS WINDOWS, LINUX, MACOS, AND OTHER UNIX-LIKE OPERATING SYSTEMS
• JENKINS IS WIDELY USED FOR CONTINUOUS INTEGRATION AND CONTINUOUS DELIVERY IN
SOFTWARE DEVELOPMENT
STEP

To configure CI pipeline with Jenkins , the first and the most obvious step is to install Jenkins, follow
this step
to install Jenkins:
❖ Launch an instance of Redhat (instance type t2.small/t3.small mostly ). Also allow port 8080, 80, 22
in
srcurity group while launching.
❖ Login into the machine using SSH on command Prompt. Now execute the following commands to
install
Jenkins:
• sudo –i
• yum install wget –y
• sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-
stable/jenkins.repo
• sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
STEP

• Sudo yum upgrade


• sudo yum install java-11-openjdk -y
• Sudo yum install Jenkins
• Sudo systemctl daemon-reload
Following Screenshots of the executed commands are attached.
You can also visit to https://www.jenkins.io/doc/book/installing/linux/#red-hat-centos for
information about
Jenkins and see the manual and commands for installing Jenkins on Red Hat Linux
Click on Start using Jenkins.
here we customize jenkins
fill the details carefully
Click on Save and finish.
here our jenkins is ready
here click on the admin section
change the password
Enter the username and password and click on sign in
here we click on configure
write the command sudo visudo
Open terminal and fire “sudo visudo”. A file gets opened , scroll down to “#Allow
root to run any command anywhere.”
Add the following with proper alignment as shown :
jenkins ALL=(ALL) NOPASSWD:ALL
click on new item
On jenkins page click on : New item -> project name -> freestyle project -> Ok
Scroll down to build steps -> add build steps -> execute shell.
Type the following commands in execute shell box as shown then apply and save :
sudo yum install httpd -y
sudo systemctl enable --now httpd
Click on Build now.
Paste the public IP on google to see the default httpd page.
Git Installation and working part
Launch a machine named “developer” and install git on it.
Now login to machine(using ssh) and execute the following set of commands :
1.sudo -i
2.yum install git -y
3.git --version
4.mkdir d1
5.cd d1/
6.vi index.html -> “write anything” -> save and
exit. 7.vi asmit.html -> “write anything” -> save
and exit. 8.git init
9.git add *
10.git commit -m “Write Commit message“
Following screenshots shows one by one execution of the above commands.
HTML code , one can write simple text also . Save and exit and do similarly for
“vibhanshu.html”.
Open “https://github.com/” and login and do following as shown :
Create a New repo -> Name it -> Click on create repo.
Scroll down & copy the following command.
Paste the copied command in developer machine.& hit enter.
Generating PAT(Personal Access Token)
To push files on Github we require PAT .Go to “https://github.com/” and
login and follow the below steps to generate PAT :

Click on profile icon Settings Developer Settings (bottom left)

Generate new token (classic) Classic Personal Access Token

Name of the token Check on repo Generate token

Copy the token & save it in a notepad file as it is required in future.


Now ,since the PAT is generated we can use it to push files on our project repository.
Come in developer machine and fire the following commands to push html files on
Github.

1.git push origin master


2.enter username
3.paste PAT

Below Screenshots shows the execution of the above steps :


We can see that the files have been added in the project repo.
Install git on jenkins machine .
Copy this URL .
On Jenkins page go to -> project1 -> Configure -> check git and paste the
copied url in repo bar .
Add the following two commands in execute shell box, then Apply -> Save -> build
now.
sudo cp index.html /var/www/html/index.html
sudo cp asmit.html /var/www/html/asmit.html
After build is successfully completed , paste the publlic ip on browser to see the
output.

Hello Everyone!!!!
Vibhanshu here.
Paste “ip/vibhanshu.html” to see this on web.

Made with love!!!


Setting up CI Pipeline
Lets finally set up the CI pipeline using github webhooks.
On Jenkins page go to : project1 -> configure -> check “GitHub hook trigger for
GITScm polling” ->apply and save -> build now.
Now lets add webhook.
On github project repo : Click on settings -> webhooks -> add webhook
Paste the url of jenkins in Payload URL and add “/github-webhook/” at the end ->
click on add webhook.
Webhook added successfully
Now come to the developer machine and do the changes in “index.html”
and “Vibhanshu.html” to see if the changes are reflected automatically.

This is “index.html”
Modifying “Vibhanshu.html”
Now fire the following commands to commit changes & push it to github repo :
git add *
git commit -m “Write Commit message“
git push origin master
enter username
Paste PAT
Refresh the web pages on browser and you’ll be able to see the changes reflected
automatically. Hence our CI pipeline is build and successful.

Project Successful!!!!!
Thank You Ashish Sir for everything!!!!!!
Thank you!

You might also like