Jenkins Git Integration – Useful for Every DevOps Professional

Last updated on Sep 14,2024 3.7K Views

Jenkins Git Integration – Useful for Every DevOps Professional

edureka.co

DevOps is certainly incomplete without Jenkins. Jenkins along with Git is a wonderful combination. So in this article, I will talk about Jenkins Git Integration and its advantages. The pointers that we are going to cover are as follows:

So let us begin with our first topic.

What is Git – Why Git Came Into Existence?

We all know “Necessity is the mother of all inventions”. Similarly, Git emerged to fulfill certain necessities that the developers faced before Git. So, let us take a step back to learn all about Version Control Systems (VCS) and how Git came into existence.

Version Control is the management of changes to documents, computer programs, large websites and other collection of information.

There are two types of VCS: 

Centralized VCS

A centralized version control system (CVCS) uses a central server to store all files and enables team collaboration. It works on a single repository to which users can directly access a central server.

Please refer to the diagram below to get a better idea of CVCS:

The repository in the above diagram indicates a central server that could be local or remote which is directly connected to each of the programmer’s workstations.

Every programmer can extract or update their workstations with the data present in the repository. They can also make changes to the data or commit to the repository. Every operation is performed directly on the repository.

Even though it seems pretty convenient to maintain a single repository, it has some major drawbacks. Some of them are:

This is where Distributed VCS solves the problem.

Distributed VCS

These systems do not necessarily rely on a central server to store all the versions of a project file. In Distributed VCS, every contributor has a local copy or “clone” of the main repository. Here everyone maintains a local repository of their own which contains all the files and metadata present in the main repository.

You will understand it better by referring to the diagram below:

As you can see in the above diagram, every programmer maintains a local repository on its own, which is actually the copy or clone of the central repository on their hard drive. They can commit and update their local repository without any interference.

They can update their local repositories with new data from the central server by an operation called “pull” and affect changes to the main repository by an operation called “push” from their local repository.

Now let us try to know about the definition of Git.

 

What is Jenkins?

Jenkins is an open-source automation tool written in Java with plugins built for Continuous Integration purposes. Jenkins is used to build and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. It also allows you to continuously deliver your software by integrating with a large number of testing and deployment technologies.

With Jenkins, organizations can accelerate the software development process through automation. Jenkins integrates development life-cycle processes of all kinds, including build, document, test, package, stage, deploy, static analysis and much more.

Jenkins achieves Continuous Integration with the help of plugins. Plugins allow the integration of Various DevOps stages. If you want to integrate a particular tool, you need to install the plugins for that tool. For example Git, Maven 2 project, Amazon EC2, HTML publisher, etc.

Advantages of Jenkins include:

You now know how Jenkins overcomes the traditional SDLC shortcomings. The table below shows the comparison between “Before and After Jenkins”.

  Before Jenkins  After Jenkins
The entire source code was built and then tested. Locating and fixing bugs in the event of build and test failure was difficult and time-consuming, which in turn slows the software delivery process.Every commit made in the source code is built and tested. So, instead of checking the entire source code developers only need to focus on a particular commit. This leads to frequent new software releases.
Developers have to wait for test resultsDevelopers know the test result of every commit made in the source code on the run.
The whole process is manualYou only need to commit changes to the source code and Jenkins will automate the rest of the process for you.

 

Why Jenkins and Git are used together?

As discussed earlier, Git is a source control manager. That is where you keep your source code for tracking all the code changes that happen over time and to baseline the versions when they are ready for release.

Jenkins, on the other hand, is a continuous integration solution. It is devised to automate most of the tasks that a developer has to do while developing a new application (code quality checks, building, archiving of build artifacts, integration testing, deployment to various environments, etc.) Without a CI solution, a developer has to spend much time doing these repetitive non-productive tasks.

Advantages:

Example:

Let us take the example of a new feature in a web application. A developer will be identified and assigned to the task, he takes the existing codebase from the Source control – say, Git, makes his changes, carries out unit testing, ensures code quality manually and checks the new code back into Git.

Then he has to build the code, deploy it into integration instance, run integration testing and once the change seems satisfactory, raise a request for production deployment. Now, if only we had a minion to take care of this testing, building, quality checks and deployment sections the poor developer could have focused better on that stuff he is really good at – implementing and improving the feature’s logic.

This minion is Jenkins. It acts as an orchestrator to run all these activities once the change is checked into source control (Git) and thus gives quick feedback to the developer whether the changes he has made are good enough for production deployment or not. It is an extremely flexible, open-source and has a ton of plugins that can do almost anything you wish it to do.

Demo

Here we will see how to integrate Git with Jenkins. There are 5 steps that you must follow :

1. Create a Sample program:

You can create any sample program that you want like Java or Python or any other program. Here we will write a simple Python program that prints Hello, World!

2. Create a Jenkins job:

3. Add this program to Github:

4. Add Git Plugin in Jenkins:

5. Configure Jenkins job to trigger the build:

So this how Jenkins Git Integration is done. With this, we have come to the end of this article on Jenkins Git Integration. I hope you have enjoyed this article.

Now that you have understood what Jenkins Git Integration is, check out this DevOps Course by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe. The Edureka DevOps Certification Training course helps learners to understand what is DevOps and gain expertise in various DevOps processes and tools such as Puppet, Jenkins, Nagios, Ansible, Chef, Saltstack and GIT for automating multiple steps in SDLC.

Got a question for us? Please mention it in the comments section and we will get back to you

Upcoming Batches For DevOps Certification Training Course
Course NameDateDetails
DevOps Certification Training Course

Class Starts on 23rd November,2024

23rd November

SAT&SUN (Weekend Batch)
View Details
DevOps Certification Training Course

Class Starts on 25th November,2024

25th November

MON-FRI (Weekday Batch)
View Details
DevOps Certification Training Course

Class Starts on 21st December,2024

21st December

SAT&SUN (Weekend Batch)
View Details
BROWSE COURSES