Continuous Integration is a development practice where developers integrate code into a shared repository frequently where each integration is verified by an automated build and automated tests. It is the most important part of DevOps that is used to integrate various DevOps stages. In this blog, we will deal with the problems developers face while writing, testing and delivering software to end users and how they solve it using CI.
In this blog, we will focus on the below topics:
In Traditional Integration or/software development cycle,
- Each developer gets a copy of the code from the central repository.
- All developers begin at the same starting point and work on it.
- Each developer makes progress by working on their own or in a team.
- They add or change classes, methods, and functions, shaping the code to meet their needs, and eventually, they complete the task they were assigned to do.
- Meanwhile, the other developers and teams continue working on their own tasks, changing the code or adding new code, solving the problems they have been assigned.
- If we take a step back and look at the big picture, i.e. the entire project, we can see that all developers working on a project are changing the context for the other developers as they are working on the source code.
The main factors that can make these problems escalate:
- The size of the team working on the project.
- The amount of time passed since the developer got the latest version of the code from the central repository.
Problems With Traditional Integration
What’s the Solution for Problems faced in Traditional Integration?
So, below are the steps to solve the above problems:
So, let us see what exactly is Continuous Integration?
What is Continuous Integration?
We Will Start with the Martin Fowler’s Definition:
Continuous Integration is a software development practice where members of a team integrate their work frequently, usually, each person integrates at least daily leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly.
Automating your build, test and deploy processes can increase the problems commonly happening on projects. So we should have a reliable method of integrating that will ensure that the errors can be found sooner than later.
What is Continuous Integration? | Edureka
Let’s move on and see what are the benefits of Continuous Integration.
Benefits of Continuous Integration
- Reduced Integration Risk: Often, working on projects means multiple people are working on the separate tasks or parts of the code which makes it risky to integrate. Debugging and solving the issue can be really painful and can potentially mean a lot of changes to the code. Integrating more frequently can help reduce these kinds of problems to a minimum.
- Higher Code Quality: Focusing more on the functionality of the code results in a higher quality product.
- The Code in Version Control works: If you commit something that breaks the build, you and your team get the notice immediately and the problem is fixed before anyone else pulls the “broken” code.
- Reduced friction between team members: Having the impartial system in place reduces the frequency of quarrels among team members.
- Easy for QA Team: Having different versions and builds of the code can help isolate and trace bugs efficiently, and it makes life easier for the QA team.
- Less time deploying: Deploying projects can be very tedious and time-consuming, and automating that process makes perfect sense.
Requirements for CI System
But you might be wondering what are the requirements for the installing of the CI system for your needs. If you want to install CI server in your own environment, you’ll need a few things first.
- Version control system (VCS). It provides a reliable method to centralize and preserve changes made to your project over time.
- Virtual Machine: For onsite solutions, you should have a spare server or at least a virtual machine. for a clean machine to build your system on is of the essential importance.
- Hosted CI Tool solutions: To avoid servers or virtual machines, you can go for hosted CI tool solutions that help in the maintenance of the whole process and offers easier scalability.
- Tools: If you opt-in for the self-hosted variant, you will need to install one of the many available continuous integration tools like Jenkins, TeamCity, Bamboo etc.
What is Jenkins – The Ultimate CI Tool
Jenkins is an open source automation tool written in Java with plugins built for Continuous Integration purpose. 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.
The image below depicts that Jenkins is integrating various DevOps stages:
Demo on Continuous Integration Using Jenkins
A company named Sanders & Fresco Private Ltd. got the project from a client which consisted of 4 modules. The Project manager divided these modules between two developers. Now to maintain the consistency in the flow of the project, they built a Continuous Delivery Pipeline where they executed all the modules in terms of jobs (a single job will have two modules). After building those jobs, they synced it in a pipeline. They also checked the build at regular intervals of time while they were developing their project. So, the path of the project which was in git hub repository was provided through Jenkins. Using the concept of CI, they built their project after a fixed interval of time which can be defined by build trigger option in Jenkins.
So, let us see how we can do this using Jenkins.
Step 1: Open the Jenkins on your designated port number in your VM.
Step 2: Click on New Item to create a new Job.
Step 3: Give the name of Freestyle Project. Here I have given Job1.
Step 4: Now go to Source Code Management-> Git. Fill the project path to pull the project from Git and Click on Apply.
Step 5: Click on Build Now.
Step 6: The Job1 will start building it.
Now we will create a project/Job2 which will build after a fixed interval of time (i.e. after every minute) which we can define by using Poll SCM.
Step 7: Click on New Item to create a new Job.
Step 8: Give the name of Freestyle Project. Here I have given Job2.
Step 9: Now go to Source Code Management-> Git. Fill the project path to pull the project from Git and Click on Apply.
Step 10: Then go to Build Trigger -> Poll SCM. Enter ” * * * * * ” to build the Job2 after every minute and click on Apply.
After clicking on Apply, a message will be displayed. Click on Save button.
Step 11: Click on Build Now.
Step 12: The Job2 will start building after every minute.
Note: To check for build status, Click on Git Polling Log. This will show details of Job2 i.e. the time at which it got built.
Now, we will be building a Jenkins Pipeline to show Continuous Delivery.
Step 13: Now go to Jenkins homepage by clicking on Jenkins.
Step 14: Click on “+” to create a pipeline view.
Step 15: Name the view and check mark “Build Pipeline View” and Click on OK.
Step 16: Go to Pipeline Flow and add Job1 in Select Initial Job. Click on OK.
Step 17: Now Click on Job1.
Step 18: Then Click on Configure.
Step 19: Go to Post-build Actions and select Build other projects. Add Job2 in Projects to build and check mark the “Trigger only if the build is stable“. Click on Save.
Step 20: Now Click on Job2 and click on Configure.
Step 21: Go to Build Triggers -> Select Build after other projects are built. Add Job1 in Projects to watch label.
Step 22: Click on the pipeline1 view you created.
Step 23: Click on Run. Job1 will start building.
After building Job1, Job2 will automatically build itself.
So, this was all about the What Is Continuous Integration and its implementation using Jenkins.
Subscribe to our youtube channel to get new updates..!
Got a question for us? Please mention it in the comments section and we will get back to you.