A GIT-GITHUB-JENKINS INTEGRATION (TASK-1)

No alt text provided for this image

To share their code what one needs to take care of is how they're managing their codes. There are many SCM (SOURCE CODE MANAGER) tools available in the market that help us in achieving the former goal and Github is one of the greatest tools among them. Github is a great platform for developers to come together and work on a particular project. It uses the approach of PAIR PROGRAMMING which is indeed a great way of sharing.

However, every tool with its advantages comes with disadvantages or we could say limitations to it. Here, the only limitation noticed is the problem of the network. There may be times when a developer might be uploading his work on GitHub but there is a network failure and then there you go, the work which was supposed to be done in half an hour, consume your couple of hours which is not acceptable in the corporate industry because here, everything is expected to be quick and fast.

This is the reason why there was a need to launch the concept of DVCS( Decentralized Version Control System). One of the most popular tools of DVCS is git. This tool allows us to download the software on our system in order to make it VCS intelligent. Through this, we could do PEER-TO-PEER sharing without a centralized system.

Although everything could be done manually, every step could be carried in a manual way, who wants to invest their time in something that could be done automatically. This automatic support is provided by Jenkins. It allows us to do everything in a continuous manner and by doing the integration of tools like git and GitHub with Jenkins, we could create projects beyond our thoughts.

Below is a task that was given by @VimalDaga sir that helps us in understanding how we can integrate these tools and the motive behind it.

  • JOB#1: If Developer pushes to dev branch then Jenkins will fetch from dev and deploy on the dev-docker environment.

--> This is the code that needs to be written in the build execute shell:-

if sudo find /root/TASKS -name /task1

then

echo "Folder exists"

else

sudo mkdir /root/TASKS/task1

fi

sudo cp -v -r -f * /root/TASKS/task1

if sudo docker ps -a | grep devenv

then

echo "Container is already running"

else

sudo docker run --dit -p 8081:80 -v /root/TASKS/task1/:/usr/local/apache2/htdocs/ --name devenv httpd

No alt text provided for this image
No alt text provided for this image
  • JOB#2: If Developer pushes to master branch then Jenkins will fetch from master and deploy on the master-docker environment. Both dev-docker and master-docker environments are in different docker containers.

--> This is the code that needs to be written in the build execute shell:-

if sudo find /root/TASKS -name /task1

then

echo "Folder exists"

else

sudo mkdir /root/TASKS/task1

fi

sudo cp -v -r -f * /root/TASKS/task1

if sudo docker ps -a | grep masterenv

then

echo "Already updated"

else

sudo docker run --dit -p 8081:80 -v /root/TASKS/task1/:/usr/local/apache2/htdocs/ --name masterenv httpd

No alt text provided for this image
No alt text provided for this image
  • JOB#3: Manually the QA team 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
No alt text provided for this image
No alt text provided for this image

I do take more time to complete this simple task due to the errors I made and then rectified it. This is the reason why I had to do a number of commits that are still their om my GitHub repo. I don't know if what I did was the most optimized way of doing this task or not, but suggestions are always acceptable.

Here is my GitHub repo: https://github.com/Nupur521/TASK1. I've manually updated all the screenshots there too.

To view or add a comment, sign in

More articles by Nupur Agarwal

Others also viewed

Explore content categories