Continuous integration (CI) is a software engineering practice in which frequent, isolated changes are immediately tested and reported on when they are added to a larger code base.
CI aims to provide rapid feedback so that when a defect is introduced into the code base, it is identified and corrected as soon as possible.
CI originated from within the Extreme Programming paradigm, which is a subset of the Agile methodology, but the principles can be applied to any iterative programming model. Traditional development approaches, such as the waterfall model, can also benefit from the use of CI methods for the construction stage. Continuous integration commonly is paired with continuous delivery, wherein steps to deliver executable code to production occur rapidly and with automation, for CI/CD.
CI common practices
According to Paul Duvall, co-author of Continuous Integration: Improving Software Quality and Reducing Risk, best practices of CI include:
- Frequent code commits;
- Developer test categorization;
- A dedicated integration build machine;
- Continuous feedback mechanisms; and
- Staging builds.
CI releases can occur at any frequency, depending on the organization that runs it and the project at hand; generally, organizations that adopt CI release more frequently than with previous software development processes. Each significant change kicks off a build. A development team incorporates CI for a number of reasons, including to receive constant feedback on the status of the software. CI detects deficiencies early in development, which makes them less disruptive, less complex and easier to resolve than later in the software development life cycle.
A development team can use automation in the CI setup to incorporate code integration and testing, which reduces time to find bugs and enables faster feedback than when these tasks are carried out manually. Automation tools help teams perform common tests as part of the CI process, such as unit, application programming interface (API) and functional tests. A unit test examines the smallest application components. An API test assesses whether or not an API can reliably perform under its expected load of requests and responses. A functional test typically evaluates larger pieces of the source code to simulate a user workflow or function. With full CI automation, scripts or integration engines manage the movement of new code through tests and build.
This automated approach is often an integral part of a CI/CD pipeline and a DevOps methodology. CD acts as an extension of CI, not an alternative. CI focuses on the build and code testing parts of the development cycle, while CD includes deployment tests and configuration automation. In CD, a development team produces and releases software to production in short cycles. Continuous deployment is a more advanced step, wherein the code releases automatically into production, live to end users.
When it incorporates CI into the development process, a dev team can bring worthwhile benefits to an organization.
CI enables shorter and less disruptive code integrations, as less code is integrated at a time, at a more frequent rate than in other dev approaches, such as waterfall. Similarly, reverted changes are less disruptive, because only isolated changes go out at once.
Bug detection is easier and faster as well, because if a bug surfaces, it will most likely be in the last integrated batch of code. Both of these benefits are the result of increased code visibility, as developers constantly add to the code base.
Continuous integration also enables continual feedback on changes, which can improve a product over time.
A development team uses CI software tools to automate parts of the application build and construct a document trail. The following are examples of CI pipeline automation tools commonly found in enterprise IT shops. Many additional tools exist for steps in the CI pipeline, such as version control, testing, builds and artifact storage, and are too numerous to detail here.
Jenkins is an open source CI automation server. Jenkins can distribute tests and builds over numerous machines. Plug-ins extend Jenkins' feature capabilities, such as those for automated unit tests and test reporting. A developer can create a project build via specific URLs, commits in a version control system, or a pre-scheduled and sequential system. Once a system is tested, Jenkins also supports the ability to deploy code with CD.
The open source GitLab repository and platform supports CI/CD. GitLab can run unit and integration tests on multiple machines and can split builds to work over multiple machines to decrease project execution times. The software also supports manual deployments for CD to staging environments and to production environments. GitLab also supports integration with tools such as Atlassian Jira, GitHub and Jenkins.
JetBrains TeamCity is an integration and management server for CI/CD. TeamCity enables developers to test code before they commit changes to a code base. If a test fails, TeamCity sends a notification. TeamCity features Build Grids, which enable developers to run multiple tests and builds for different platforms and environments. TeamCity includes support for Docker, Jira and other programs.