Integrating Jenkins with GitHub and 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⚡
Make a repository on GitHub first ⏩
Now Uploading file in Master branch ⏩
Now change the branch type: git checkout dev. Now, all the codes from master
branch are present in the dev
branch.
Now upload files in dev branch
Now, we have set up 2 branches in GitHub successfully 😀
Now it’s time to start Jenkins
I am using RHEL8 OS to start Jenkins
Command: systemctl start jenkins
Type RHEL8 IP and port no. 8080 in BROWSER , login with as username
and password.
Next move, Job Creation👨💻
⏩ 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, select
GitHub hook trigger for GITScm polling
- In the Build Section, type the following script in Execute Shell section:
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. Now save the job by clicking Save button.
Bravo!!!… Job-1 run successfully 😃
⏩ 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, select
GitHub hook trigger for GITScm polling
6. In the Build Section, type the following script in Execute Shell Section:
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
fi
sudo cp -rvf * /Masterws
7. Now save the job by clicking Save button.
Bravo!!!… Job-2 run 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.
Now Save the Job-3.
Hurray!!! Job-3 run successfully…. 😍
😎 Now let’s cross check the merge status
So, Our Task has been done successfully… 😉✌
Thanks for reading… 📃
GitHub Link:- https://github.com/Krishna3-cloud/Jenkins-Task1.git