Integrating Github, Jenkins, Docker.

Anurag Mittal
5 min readJun 18, 2020

Objective — creating one job in Jenkins for fetch the data from Dev1 branch and deploy in the testing environment webserver . Create second job for fetch the data from master branch and deploy into production environment. Creating one more job that will check if the code is running fine on testing environment then merge both branches and again trigger the second job so that updates our visible on webserver of production environment.

Github Repository — https://github.com/anurag08-git/webproject

❗️TASK-1 ❗️

JOB#1
If Developer push 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-docke environment.
both dev-docker and master-docker environment are on different docker containers.

JOB#3
Jenkins will automatically check website running in dev-docker environment. If it is running fine then Jenkins will merge the dev branch to master branch and trigger #job 2

Let’s start the process-

Step 1 . Creating First job

Giving URL of the Github repository to the Jenkins. Jenkins from this URL download the code from dev1 branch of github repository.

Adding a Trigger in this job. Poll SCM will go to dev1 branch of github repository in every 1 min and check if developer push any code or not. If it push than jenkins will download it.

Copy this code that jenkins download from github repository to a folder in base operating system . check if any os is running with name weba. If it is not running then create one os through docker and put this code in this docker container . This container act as testing environment.

Step 2. Creating second job

Giving URL of the Github repository to the Jenkins. Jenkins from this URL download the code from master branch of github repository.

Adding a Trigger in this job. Poll SCM will go to master branch of github repository in every 1 min and check if developer push any code or not. If it push than jenkins will download it.

Copy this code that jenkins download from github repository to a folder in base operating system . check if any os is running with name webb. If it is not running then create one os through docker and put this code in this docker container . This container act as production environment.

Step 3. Creating the third job

Giving URL of the Github repository to the Jenkins.

Creating a environment in this job that will merge dev1 branch to master branch only when if the site running from dev1 branch code in testing environment works fine.

This third job will trigger only when first job build successful.

Here I am creating one automation for testing that site running in testing environment is working fine or not. If it is working fine then this job builds successfully and merge the dev1 branch to master branch and trigger job 2.

From the below code jenkins automatically detect the site on teting environment. We don’t have to check manually that site is running fine or not.

After this job build successful it will trigger second job . Now second job will create container and o that container same site is running that is running on testing environment.

Step 4. Creating one build pipeline for proper view of the task.

Adding the initial job that is first job in the pipeline.

Step 5. Developer push the code to dev1 branch. As soon as developer commit , code automatically push to dev1 branch of github repository.

As you can see code has pushed successfully to the dev1 branch of github repoository

Now pipeline that we have craeted will do the work.

Here you can see pipeline build all the jobs successfully

I am seeing the site running on testing environment. It means job 1 has build successfully

Here you can see jenkins merge dev1 branch with master branch means job3 has been build successfully

Now the second job has been build successfully. Now we can see the same site on production environment that is running on testing environment.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Anurag Mittal
Anurag Mittal

Written by Anurag Mittal

Learning the new technologies like mlops, devops, hybrid multi cloud to enhance my skills.

No responses yet

Write a response