GitHub +Jenkins +Docker
🎗️ TASK DESCRIPTION 🎗️
JOB#1: If a Developer pushes their code to dev
branch then Jenkins will fetch from dev
and deploy on dev-docker
environment.
JOB#2: If Developer push to master
branch then Jenkins will fetch from master
and deploy on master-docker
environment.
JOB#3: Jenkins will check (test) for the website running in the dev-docker
environment. If it is running fine then Jenkins will merge the dev
branch to master
branch and trigger JOB#2.
⚡Let’s Begin 😀
⏩ First, create a repository in GitHub.
⏩ Uploading file in master branch
⏩ change the branch, type: git checkout dev
Now, all the codes from master
branch are present in the dev
branch.
Uploading file in dev branch
Now, we have set up 2 branches in GitHub successfully 😀
⏩ For tunneling, i used ngrok software.
🔰 Let’s start Jenkins in RHEL 8 : systemctl start jenkins
Type RHEL8 IP and port no. 8080 in BROWSER , login with as username
and password.
🔰 NOW , Let’s Create Jobs 😀
⏩ For JOB-1
- Select
new item
option from the Jenkins menu. - Assign a name to the Job ( Here,
JOB-1
)and selectFreestyle
project. Configure Job
option, set the configurations….- In Source Code Management section, we select Git and mention the URL of our GitHub Repository and select the branch as
dev
. - In the Build Triggers section, we select
GitHub hook trigger for GITScm polling
- In the Build Section, type the following script in Execute Shell:
if sudo docker ps | grep dev_os
then
echo "dev is already Running"
else
sudo docker run -d -i -t -p 8081:80 -v /devws:/usr/local/apache2/htdocs/ --name dev_os httpd
fisudo cp -rvf * /devws
7. click on the Save option.
we have created JOB-1 successfully 😀
⏩ NOW For JOB-2
- Select
new item
option from the Jenkins menu. - Assign a name to the Job ( Here,
JOB-1
)and selectFreestyle
project. Configure Job
option, set the configurations….- In Source Code Management section, we select Git and mention the URL of our GitHub Repository and select the branch as
dev
. - In the Build Triggers section, we select
GitHub hook trigger for GITScm polling
6. In the Build Section, type the following script in Execute Shell:
if sudo docker ps | grep master_os
then
echo "master is already Running"
else
sudo docker run -d -i -t -p 8082:80 -v /masterws:/usr/local/apache2/htdocs/ --name master_os httpd
fisudo cp -rvf * /masterws
7. click on the Save option.
created JOB-2 successfully 😀
⏩ For JOB-3
- Select
new item
option from the Jenkins menu. - Assign a name to the Job ( Here,
JOB-3
)and select aFreestyle
project. - In
Configure Job
option, set the configurations… - In the Source Code Management section, select Git and mention the URL of our GitHub Repository and select the branch to build as
dev
. - In Additional Behavior , select
Merge Before Build
- set the Name of the Repository as
origin
, Set the Branch to Merge to asmaster
- In Post Build Actions ,select Git Publisher , check Push only if the build succeeds and Merge Results options.
8. Click on save .
created JOB-3 successfully 😀
✴️ Let’s cross check the merge status
⚡Successfully done all the Jobs ✌️
✴️ Now we check the pages
🔰 Successfully Completed the task 😀✌️
GitHub link : https://github.com/Anujakumari/Jenkins_Task_1.git
Thanks for Reading !! 🙌🏻😁📃
🔰 Keep Learning !! Keep Sharing !!
LinkedIn profile : https://www.linkedin.com/in/anuja-kumari-4a62581aa/
GitHub : https://github.com/Anujakumari