Continuous integration explained

Continuous integration (CI) is the practice of integrating source code changes frequently and ensuring that the integrated codebase is in a workable state.

Typically, developers merge changes to an integration branch, and an automated system builds and tests the software system. Often, the automated process runs on each commit or runs on a schedule such as once a day.

Grady Booch first proposed the term CI in 1991,[1] although he did not advocate integrating multiple times a day, but later, CI came to include that aspect.[2]

History

The earliest known work on continuous integration was the Infuse environment developed by G. E. Kaiser, D. E. Perry, and W. M. Schell.[3]

In 1994, Grady Booch used the phrase continuous integration in Object-Oriented Analysis and Design with Applications (2nd edition)[4] to explain how, when developing using micro processes, "internal releases represent a sort of continuous integration of the system, and exist to force closure of the micro process".

In 1997, Kent Beck and Ron Jeffries invented extreme programming (XP) while on the Chrysler Comprehensive Compensation System project, including continuous integration.[5] Beck published about continuous integration in 1998, emphasising the importance of face-to-face communication over technological support.[6] In 1999, Beck elaborated more in his first full book on Extreme Programming.[7] CruiseControl, one of the first open-source CI tools,[8] was released in 2001.

In 2010, Timothy Fitz published an article detailing how IMVU's engineering team had built and been using the first practical CI system. While his post was originally met with skepticism, it quickly caught on and found widespread adoption as part of the lean software development methodology, also based on IMVU.

Practices

The core activities of CI are developers co-locate code changes in a shared, integration area frequently and that the resulting integrated codebase is verified for correctness. The first part generally involves merging changes to a common version control branch. The second part generally involves automated processes including: building, testing and many other processes.

Typically, a server builds from the integration area frequently; i.e. after each commit or periodically like once a day. The server may perform quality control checks such as running unit tests[9] and collect software quality metrics via processes such as static analysis and performance testing.

Related practices

This section lists best practices from practitioners for other practices that enhance CI.

Build automation

Build automation is a best practice.[10] [11]

Atomic commits

CI requires the version control system to support atomic commits; i.e., all of a developer's changes are handled as a single commit.

Committing changes

When making a code change, a developer creates a branch that is a copy of the current codebase. As other changes are committed to the repository, this copy diverges from the latest version.

The longer development continues on a branch without merging to the integration branch, the greater the risk of multiple integration conflicts[12] and failures when the developer branch is eventually merged back. When developers submit code to the repository they must first update their code to reflect the changes in the repository since they took their copy. The more changes the repository contains, the more work developers must do before submitting their own changes.

Eventually, the repository may become so different from the developers' baselines that they enter what is sometimes referred to as "merge hell", or "integration hell",[13] where the time it takes to integrate exceeds the time it took to make their original changes.[14]

Testing locally

Proponents of CI suggest that developers should use test-driven development and toensure that all unit tests pass locally before committing to the integration branch so that one developer's work does not break another developer's copy.

Incomplete features can be disabled before committing, using feature toggles.

Continuous delivery and continuous deployment

Continuous delivery ensures the software checked in on an integration branch is always in a state that can be deployed to users, and continuous deployment automates the deployment process.

Continuous delivery and continuous deployment are often performed in conjunction with CI and together form a CI/CD pipeline.

Version control

See main article: Version control.

Proponents of CI recommend storing all files and information needed for building in version control, (for git a repository); that the system should be buildable from a fresh checkout and not require additional dependencies.

Martin Fowler recommends that all developers commit to the same integration branch.[15]

Automate the build

See main article: Build automation.

Build automation tools automate building.

Proponents of CI recommend that a single command should have the capability of building the system.

Automation often includes automating the integration, which often includes deployment into a production-like environment. In many cases, the build script not only compiles binaries but also generates documentation, website pages, statistics and distribution media (such as Debian DEB, Red Hat RPM or Windows MSI files).

Commit frequently

Developers can reduce the effort of resolving conflicting changes by synchronizing changes with each other frequently; at least daily. Checking in a week's worth of work risks conflict both in likelihood of occurrence and complexity to resolve. Relatively small conflicts are significantly easier to resolve than larger ones. Integrating (committing) changes at least once a day is considered good practice, and more often better.[16]

Daily build

Building daily, if not more often, is generally recommended.

Every commit should be built

The system should build commits to the current working version to verify that they integrate correctly. A common practice is to use Automated Continuous Integration, although this may be done manually. Automated Continuous Integration employs a continuous integration server or daemon to monitor the revision control system for changes, then automatically run the build process.

Every bug-fix commit should come with a test case

When fixing a bug, it is a good practice to push a test case that reproduces the bug. This avoids the fix to be reverted, and the bug to reappear, which is known as a regression.

Keep the build fast

The build needs to complete rapidly so that if there is a problem with integration, it is quickly identified.

Test in a clone of the production environment

Having a test environment can lead to failures in tested systems when they deploy in the production environment because the production environment may differ from the test environment in a significant way. However, building a replica of a production environment is cost-prohibitive. Instead, the test environment or a separate pre-production environment ("staging") should be built to be a scalable version of the production environment to alleviate costs while maintaining technology stack composition and nuances. Within these test environments, service virtualisation is commonly used to obtain on-demand access to dependencies (e.g., APIs, third-party applications, services, mainframes, etc.) that are beyond the team's control, still evolving, or too complex to configure in a virtual test lab.

Make it easy to get the latest deliverables

Making builds readily available to stakeholders and testers can reduce the amount of rework necessary when rebuilding a feature that doesn't meet requirements. Additionally, early testing reduces the chances that defects survive until deployment. Finding errors earlier can reduce the amount of work necessary to resolve them.

All programmers should start the day by updating the project from the repository. That way, they will all stay up to date.

Everyone can see the results of the latest build

It should be easy to find out whether the build breaks and, if so, who made the relevant change and what that change was.

Automate deployment

Most CI systems allow the running of scripts after a build finishes. In most situations, it is possible to write a script to deploy the application to a live test server that everyone can look at. A further advance in this way of thinking is continuous deployment, which calls for the software to be deployed directly into production, often with additional automation to prevent defects or regressions.[17] [18]

Benefits

CI benefits include:

Risks

Risks of CI include:

External links

Notes and References

  1. Book: Booch, Grady . Object Oriented Design: With Applications . . 1991 . 9780805300918 . 209 . Grady Booch . 18 August 2014.
  2. Beck . K. . 1999 . Embracing change with extreme programming . Computer . 32 . 10 . 70–77 . 10.1109/2.796139 . 0018-9162.
  3. Kaiser . G. E. . Perry . D. E. . Schell . W. M. . 1989 . Infuse: fusing integration test management with change management . Proceedings of the Thirteenth Annual International Computer Software & Applications Conference . Orlando, Florida . 552–558 . 10.1109/CMPSAC.1989.65147. 10.1.1.101.3770 .
  4. Book: Booch, Grady . Object-Oriented Analysis and Design with applications . December 1998 . 2nd . 2 December 2014 . 19 August 2019 . https://web.archive.org/web/20190819035559/http://www.cvauni.edu.vn/imgupload_dinhkem/file/pttkht/object-oriented-analysis-and-design-with-applications-2nd-edition.pdf . dead .
  5. Web site: Continuous Integration . Fowler . Martin . 1 May 2006 . 9 January 2014.
  6. Beck . Kent . 28 March 1998 . Extreme Programming: A Humanistic Discipline of Software Development . Lisbon, Portugal . . 1 . 4 . 9783540643036 . Fundamental Approaches to Software Engineering: First International Conference.
  7. Book: Beck, Kent . Extreme Programming Explained . Addison-Wesley Professional . 1999 . 978-0-201-61641-5 . 97 . Beck, Extreme Programming Explained . Kent Beck . registration.
  8. News: 1 February 2018 . A Brief History of DevOps, Part III: Automated Testing and Continuous Integration . CircleCI . 19 May 2018.
  9. Web site: Continuous integration . Radigan . Dan . Atlassian Agile Coach.
  10. [OSLC] Possible new Working Group – Automation ]. 1 January 2010 . Brauneis . David . open-services.net Community . 16 February 2010 . https://web.archive.org/web/20180901173720/http://open-services.net/pipermail/community_open-services.net/2010-January/000214.html . 1 September 2018 . dead .
  11. Web site: Rails Deployment and Automation with ShadowPuppet and Capistrano . Taylor . Bradley . Rails machine . . dead . https://archive.today/20121202054105/http://blog.railsmachine.com/articles/2009/02/10/rails-deployment-and-automation-with-shadowpuppet-and-capistrano/ . 2 December 2012 . 16 February 2010 . Taylor, Rails Deployment and Automation with ShadowPuppet and Capistrano.
  12. Book: Duvall, Paul M. . Continuous Integration. Improving Software Quality and Reducing Risk . Addison-Wesley . 2007 . 978-0-321-33638-5.
  13. Web site: Integration Hell . Cunningham . Ward . Ward Cunningham . 5 August 2009 . WikiWikiWeb . 19 September 2009.
  14. Web site: What is Continuous Integration? . Amazon Web Services.
  15. Web site: Practices . Fowler . Martin . Martin Fowler (software engineer) . Continuous Integration . article . 29 November 2015.
  16. Book: Continuous Integration: Improving Software Quality and Reducing Risk. Paul M. Duvall. Steve Matyas. Andrew Glover. 978-0-321-33638-5. Addison-Wesley Professional. 2007.
  17. Web site: Continuous deployment in 5 easy steps . Ries . Eric . 30 March 2009 . Radar . O’Reilly . 10 January 2013.
  18. Web site: Continuous Deployment at IMVU: Doing the impossible fifty times a day . Fitz . Timothy . 10 February 2009 . Wordpress . 10 January 2013.
  19. Junpeng . Jiang . Zhu . Can . Zhang . Xiaofang . July 2020 . An Empirical Study on the Impact of Code Contributor on Code Smell . International Journal of Performability Engineering . 16 . 7 . 1067–1077 . 10.23940/ijpe.20.07.p9.10671077. 222588815 .
  20. Laukkanen . Eero . 2016 . Problems, causes and solutions when adopting continuous delivery—A systematic literature review . Information and Software Technology . 82 . 55–79 . 10.1016/j.infsof.2016.10.001 . free.
  21. Web site: Assessing challenges of continuous integration in the context of software requirements breakdown: a case study . Debbiche . Adam.