DevOps CI Environment Setup using- Jenkins, Git, Docker

DevOps CI Environment Setup using- Jenkins, Git, Docker

In this task we are gonna built a environment in which we assume two or more developers are working, One is senior, and the other's are junior. Both developer push code to Github i.e both has push code to the allocated branches. And the task of Jenkins is fetching code from GitHub and deploy to environment. The Code of Senior Developer is deployed directly to the production environment but the code of Junior Developer first tested by the team and if approved then they deployed to the same production environment, here we use git merge. But for testing and Production, we have to use the same type of environment. Let's Check the implementation -:

Step -1 : Create repo in github and don't intitalize readme file. Open git bash and do the following :

Create directory
run git init for initalization
Create Files : Index.html , about.html , ....;
Add files to Staging area Using : git add .
Run this command to connect to remote repo:
                               git remote add origin https://lnkd.in/gu42xTX

Run this command for first commit: git push -u origin master

· Add a new branch for other developer so that he/she can also start development on the same project. After that add this branch to remote repo also. After this we can add one hook that will automate the task of push means, when developer hit commit the push command also run automatically.

git branch branch_name
git git push -u origin branch_name

cd .git/hooks  
        #!/bin/bash
        echo "Github Code"
        git push   

Step -2: Here we create total 5 Jobs in Jenkins and every job is assigned a task that they completed automatically, we just need to set up that. Let's check

Job1 - The task of job 1 is to fetch the data from Github and copy it into a folder in RedHat 8. In this job, the Jenkin is monitoring the GitHub whenever any change in GitHub found it then run the job. For monitoring, we set trigger that is POLL SCM (Poll SCM periodically polls the SCM to check whether changes were made (i.e. new commits) and builds the project if new commits were pushed since the last build).


No alt text provided for this image

Job 2: The task of job 2 is same as job1 but it pulls Junior developer data from GitHub or you can say branch 2 data that is allocated and save it into some test folder in RedHat 8.

No alt text provided for this image

Job 3: The task of job 3 is to deploy the code to the production environment. For deployment, we use docker because the docker is very fast. In this job, we also need to do Job Chaining because when Job 1 runs successfully after that it will run. We also need to PATTING while launching a docker container because it runs in an isolated environment. In order to make it public we need to do PATTING.

No alt text provided for this image

Job 4: The task of job 4 is the same as Job 3 but it deploy code to testing environment. For deployment, we use docker because the docker is very fast. In this job, we also need to do Job Chaining because when Job 2 runs successfully after that it will run. We also need to PATTING while launching a docker container because it runs in an isolated environment. In order to make it public we need to do PATTING.

No alt text provided for this image

Job 5: The task of Job 5 is to merge data of branch of Junior Developer with the senior developer when the testing team approved that code is working code. In our case we assume that the code of junior Developer is working fine, so we need to merge the code. In this first, we need to set up SCM with credentials and specify branch that we need to merged with. After that click on Additional behaviour then merge before built and fill name of repo in my case it is origin and branch merge to that is master.

No alt text provided for this image

and run this manually. After that setup trigger that builds remotely. We also need to setup Post- built action in this   Check: force push, Branch to push: master, Target remote name: origin

No alt text provided for this image

As you know, we set up built remote trigger so we have a URL that QTA team will run on successful code execution.

要查看或添加评论,请登录

社区洞察