CI/CD: All you need to know
Unless you are someone who stays miles away from programming, then the chances of you not hearing about CI/CD or tools like Jenkins or GitLab is quite slim. This is because CI/CD is used extensively across the software life cycle in various organizations due to its wide array of uses, such as better quality of code, better efficiency of developers, and faster builds to name a few.
But at the same time, not every application needs CI/CD and some can work well without it. In fact, it can often turn counterintuitive under various circumstances. For instance, if you are looking for less frequent code changes or less frequent testing cycles, then employing CI/CD may not be a great idea.
In this post, we are going to understand in depth about CI/CD and the reasons why it became so popular over the years.
Table of Contents
- What is Continuous Integration?
- What is Continuous Delivery?
- CI/CD workflow
- Benefits of CI/CD
- When to use and not use CI/CD?
What is Continuous Integration?
CI or Continuous Integration is a practice in development where you merge codebases of all the developers multiple times a day into a shared repository. This entire practice revolves around setting up a consistent build, package, and testing process in a project.
When there is a consistency in integration, the teams will commit code changes more frequently. You can detect bugs and integration problems much earlier in time due to the better collaboration in development. Also, the developers end up writing more modular code that is quite easy to support. All these results in overall better software quality.
Continuous Integration is not something new as it has been a thing since the 90s. However, the name CI was coined a little later and also the working has modified a bit, but the overall concept remains the same which is – combine changes in code in small units but multiple times in a day and test whether the project builds and runs once those changes have been implemented. It began as a practice to avoid the notorious merge issues that keep cropping up regularly.
What is Continuous Delivery?
CD or Continuous Delivery is another practice in development that enables you to deploy your merged code into production without the need of someone manually doing it. CD continues from where CI left and as it takes the stored code in the repository through CI and constantly delivers it to production.
CD is quite useful especially if your team is working on multiple environments such as development and testing. CD ensures that any code changes are automatically pushed to all of them. The main objective of the CD is to clear all the obstacles automatically that can sprout at the time of deployment or release. Since every step is automated in the build process, the release of the code can be done safely at any point in time without worrying about any last-minute issue.
What is CI/CD Pipeline
CI/CD pipeline is a runnable specification of all the steps that have to be performed to deliver an updated version of the application. As we have seen earlier, this pipeline is entirely automated and needs no human intervention.
The CI/CD pipeline typically consists of 4 stages:
1) Source stage
The first stage is all about triggering the source code repository. And this happens when there is a change in the code that automatically triggers a notification to the CI/CD tool. The tool then runs the corresponding pipeline. Any scheduled or user-initiated workflows and results of other pipelines are also common triggers.
2) Build stage
The second stage is the merging of the source code and its dependencies to build the runnable instance of the software. This can then be shipped to the end-users. Regardless of which language the code is written, all cloud-native software is deployed majorly with Docker and this stage typically builds the Docker containers. In case you are unable to pass the build stage, it means there is a fundamental problem in the configuration.
3) Test stage
This stage is all about running automated tests and validating the code for any bugs and delivering a bug-free product to the end-users. This stage can run for hours depending on the complexity of the project. Some complex projects might require multiple smoke tests and end-to-end integration tests while simple projects might not require up to that level. In case you are unable to pass the test stage, it means the developers introduced some issues at the time or writing the code. Sooner the issue reaches the developers, faster they can rectify it.
4) Deploy stages
This is the last stage where we deploy the runnable instance of the code that has passed all the previous three stages. Code can be deployed to multiple environments such as staging or production.
Benefits of CI/CD
There are many benefits to using CI/CD. Here we have covered the top 5 benefits of CI/CD that all developers love:
1) Faster release
This is the most obvious benefit that you will experience once you start using CI/CD in your project. A project with CI/CD will have faster release rates as the builds are faster, less manual interaction and the deployment happens regularly. The entire duration of the SDLC drastically reduces.
2) Efficient testing & fault isolation
Your testing process improves significantly and you are left with minimal bugs when using CI/CD. This is because the testing is done on small chunks of changes which ensures that the accuracy of the testing improves. Not just that, fault isolation becomes much easier as you can easily identify when and where the fault occurred. This limits the bugs even further. This helps in reducing the chances of any major issue causing severe issues to the application.
3) Improved team dynamics
When your daily development tasks are reduced to small bits, it makes your life as a developer all too simpler. This not only uplifts the team’s spirits but makes them highly efficient. CI/CD is an excellent way to receive continuous feedback from the team, thereby improving the overall transparency amidst them. The best part about CI/CD is you get rapid feedback from both the internal team and the customers thereby letting you to course correct in a short span.
4) High quality of code
If you are part of one of those projects, where the code quality is of supreme importance, then CI/CD can be embraced to achieve that. Due to the multiple and repetitive steps in a CI/CD, the errors are easily caught and fixed soon. This automatically improves the quality of the code.
When not to opt for CI/CD
Though it makes great sense to adopt CI/CD for every project, there are certain times when it is best not to embrace it. Implementing CI/CD doesn’t come cheap and requires a lot of effort and money especially when you have an existing project running without CI/CD. If you are starting from scratch then it is a different ball game.
When you add CI/CD workflows to your existing project, you will end up changing the entire workflow and automating the testing process. All these are great in the long run but setting it up requires a lot of man-hours which might be tough to manage if you are already on a shoe-string budget. A project with CI/CD requires continuous support which can be difficult for an organization that offers diverse services.
If you are looking to streamline your project and experience better efficiency and lower bugs, then embracing CI/CD is a wise choice. However, organizations need to weigh the pros and cons of CI/CD and decide what is more important to them. Having said that most of the organizations these days have already an efficient CI/CD tools like Jenkins or Azure DevOps in place which is playing a major role in their day to day development.