Continuous Integration explained with jenkins deployment
Continuous integration is a coding philosophy and set of practices that encourage development teams to make small code changes and check them into a version control repository regularly. Most modern applications necessitate the development of code across multiple platforms and tools, so teams require a consistent mechanism for integrating and validating changes. Continuous integration creates an automated way for developers to build, package, and test their applications. A consistent integration process encourages developers to commit code changes more frequently, resulting in improved collaboration and code quality.
Continuous integration necessitates the participation of all developers working on a project. The results must be transparently available to all team members, and the build status must be reported to developers when they change the code. If the main code branch fails to build or pass tests, an alert is usually sent to the entire development team, which should take immediate action to get it back to a “green” state.
Why is Continuous Integration required?
In business, especially in new product development, we rarely have the time or ability to figure everything out ahead of time. Taking smaller steps allows us to make more accurate estimates and validate them more frequently. A shorter feedback loop implies more iterations. And learning is driven by the number of iterations rather than the number of hours invested.
Working in long feedback loops is risky for software development teams because it increases the likelihood of errors and the amount of work required to integrate changes into a working version of the software.
Small, controlled changes can be made regularly. Developers can avoid repetitive work and human error by automating all integration steps. A CI tool monitors the central code repository and runs all automated tests on every commit, rather than having people decide when and how to run tests. It accepts or rejects the code commit based on the results of all tests.
Features of CI
Here are some crucial characteristics and advantages of continuous integration:
- To all holders of a stack, the entire build, testing, and deployment process should be visible.
- The built environment ought to be close to the area used for production.
- You can test the production CI environment’s clone.
- Constant availability of a current build is one of the benefits of continuous integration.
- permits you to only maintain one source repository
Benefits of continuous integration
To understand more about the importance of CI, here are some of its benefits:
The frequent testing and deployment of code reduce the risk level of the project because code defects and bugs can now be detected earlier. This means that these bugs and errors are simple to fix and take less time, making the overall process less expensive. The general operation accelerates the feedback mechanism, making communication smoother and more effective.
Early bug detection and quick bug fixes
Numerous different kinds of checks may be included in the automated testing process:
- Validate application behavior from the viewpoint of the customer;
- contrasting coding practices with accepted industry practices;
- Check code for typical security flaws;
- Find security updates in dependencies on third parties;
Including these tests in your CI pipeline, tracking their results, and improving them is probably the easiest way to keep your software at an excellent standard. A CI tool gives developers immediate feedback on whether the new code they wrote works, introduces bugs, or represents a quality regression. Early errors are the easiest to correct.
Increase the frequency with which working software is delivered
Continuous integration allows your team to automatically build and test every source code change. This serves as the foundation for your overall software delivery process to be efficient, resilient, fast, and secure.
The interval between the development, integration, testing, and deployment of the application is drastically shortened. When this period is shortened, any potential waiting periods in the middle are also shortened. No matter what, CI makes sure that all these processes continue to take place. Continuous Integration, Continuous Deployment, and Continuous Delivery are the three terms we came across. We need to consider how the three differ from one another.
Higher Product Quality
The detection of errors is made simple by features like code review and code quality detection that are provided by continuous integration. Emails or SMS messages will alert the user if the code does not conform to the standard level or contains an error. Developers can continually hone their coding skills with the aid of code reviews.
Code sharing is made simple and regularized by the Continuous Delivery workflow, which works in conjunction with the Continuous Integration process. As a result, team members can work together more openly during the process. Long-term, this increases communication efficiency and ensures that everyone in the organization is speaking the same language.
Challenges of Continuous Integration
Here are some of the challenges of continuous integration:
That is most likely a subjective disadvantage, but it is still a common one. Not all developers are willing to take on the challenge of relearning processes to save time. They may prefer to complete their tasks without the use of bureaucratic procedures. The practices outlined above, however, should overcome the unwillingness to learn something new.
Organizational Culture Shifts
When it comes to software development, many businesses still favor traditional methodologies. They would need to retrain their staff and alter current procedures to implement continuous integration. Most businesses tend to be resistant to change and want to quickly achieve their goals.
Adopting CI/CD-based development necessitates significant effort, time, and financial investment. Hiring and retaining DevOps engineers, as well as putting your repositories in Git, are just a few of the processes that must be completed. However, there is some good news. All of the processes are manageable. All you need is a good budget planning strategy.
Not Easy to Maintain
It is not easy to create an automated code repository. Teams must create the appropriate testing infrastructure and devote more time to writing test cases than to writing code. At first, this might cause them to lag and lose hope of finishing their projects on time. If the testing suite isn’t stable, it might perform flawlessly on some days but not on others. The investigation into what happened would then require more time from the team.
Best Continuous Integration Tools and Services
You can currently choose from a wide range of continuous integration tools.
Their number is so large that managers are frequently stunned as to how to select the best continuous integration tools for their projects. If the tool you’ve chosen lacks the following technical features, keep looking.
Features of ideal continuous integration tools include:
- Cloud compatibility – A good CI tool should make it simple to transfer data to and from the cloud.
- Deployment options – A CI tool must be simple to use and enable trouble-free deployment.
- Safety and security – Whether it is open-source or commercial, a practical CI tool shouldn’t pose any security risks to the project data.
- Integration options – Your CI tool should be able to connect to other project-related software and services.
- Robust ecosystem – A CI tool aims to expedite project release and eliminate additional development efforts. Make sure the tool won’t cause any bottlenecks for your project before implementing it.
A CI tool needs to be both technically sophisticated and meet the needs of your project and business. You might want to get a paid-for CI solution or a free open-source one depending on your business plan. Additionally, you should confirm that the tool of choice enables simple project management and transfer. Choosing a tool that can visualize the Content is another smart move.
Jenkins installation on Ubuntu using AWS Ec2 instance
I’ll show how to install Jenkins using an E2E process on an AWS EC2 Linux instance. It is advised that we read the official Jenkins deployment guide before we start the deployment process to know all the precise requirements and processes, we must meet to set up and execute Jenkins.
Phase 1: Creating the configuration script
So, the Jenkins deployment on Linux is what we’re looking for. The commands that we must execute are listed below:
Let’s write the script we’ll use to set up the Linux machine.
Part1: Deploying JDK
JDK deployment as it was one of the requirements for installing Jenkins
sudo apt update -y
sudo apt install openjdk-8-jre -y
Part 2: Deploying Maven
We also need to install Maven to enable Jenkins’ build creation process (Otherwise this step will fail)
$ sudo apt install maven -y
Part 3: Deploying Jenkins
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \ /usr/share/keyrings/jenkins-keyring.asc > /dev/null echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \ https://pkg.jenkins.io/debian-stable binary/ | sudo tee \ /etc/apt/sources.list.d/jenkins.list > /dev/null sudo apt-get update sudo apt-get install jenkins
The final script:
#!/bin/bash sudo apt update -y sudo apt install openjdk-8-jre -y sudo apt install maven -y curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \ /usr/share/keyrings/jenkins-keyring.asc > /dev/null echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \ https://pkg.jenkins.io/debian-stable binary/ | sudo tee \ /etc/apt/sources.list.d/jenkins.list > /dev/null sudo apt-get update sudo apt-get install jenkins
Phase 2: Creating the EC2 instance
This stage involves setting up and configuring the Ubuntu instance:
Open AWS EC2 instance creation page : https://us-east1.console.aws.amazon.com/ec2/v2/home?region=us-east-1#Instances: and lunch a new instance:
Select the ubuntu version:
Select instance type:
In this example, I will use the primary t2.micro instance type as it covers all the prerequisites to install Jenkins.
Open the “Advanced details” section and copy the script details under “User data”
Configure security group
So, Jenkins is a web server, and we can access it from the web using port 8080
Create a new Key Pair:
Create an instance and access Jenkins:
Open a browser and type http://22.214.171.124:8080:
The retrieval of Jenkins credentials will be the following step that is required. We’ll need to use an SSH connection to get access to the instance to do that.
Once you have access to the instance, use cat to open the security file and get the pass:
root@ip-172-31-47-2:/var/lib/jenkins# cat /var/lib/jenkins/secrets/initialAdminPassword e12e28a79e4b48e8a7b1c6979965960a root@ip-172-31-47-2:/var/lib/jenkins#
Copy it to the Jenkins log-in page and click “Continue”
The ability of Jenkin to use plug-ins to carry out laborious and time-consuming tasks is thus its main strength. Let’s add NodeJS as our build Toll and start the deployment
After the installation is finished, you will be prompted for your credentials:
Now we all set, press “Save and Finish”
Important clarification regarding the EC2 instances that we are using is that the IP is changing after each reboot (we can fix it using Elastic/static IPs but that is in future articles). So once you reboot your machine, please remember to retrieve the new IP so you can still get access to your Jenkins server (This is for learning purposes only 🙂
Published on Java Code Geeks with permission by David Tzemach, partner at our JCG program. See the original article here: Continuous Integration explained with jenkins deployment
Opinions expressed by Java Code Geeks contributors are their own.