Continuous integration: Difference between revisions

Content deleted Content added
Maintain a code repository: Corrected the spelling of artefacts to artifacts.
m Reverted edits by 45.70.53.159 (talk) (HG) (3.4.13)
 
(45 intermediate revisions by 27 users not shown)
Line 1:
{{short description|Software development practice basedof onbuilding frequent submission ofand granulartesting changesfrequently}}
{{more footnotes|date=July 2016}}
{{Use dmy dates|date=April 2022}}
{{EngvarB|date=April 2022}}
{{Software development process}}
[[File:Continuous Integration.jpg|thumb|right|Sketch of [[flow diagram]] for continuous integration]]
In [[software engineering]], '''continuous integration''' ('''CI''') is the practice of merging all developers' working copies to a shared [[Trunk (software)|mainline]] several times a day.<ref name="martinfowler" /> [[Grady Booch]] first proposed the term CI in [[Booch method|his 1991 method]],<ref>{{Cite book |last=Booch |first=Grady |url=https://books.google.com/books?id=w5VQAAAAMAAJ&q=continuous+integration+inauthor:grady+inauthor:booch |title=Object Oriented Design: With Applications |publisher=[[Benjamin Cummings]] |year=1991 |isbn=9780805300918 |page=209 |author-link=Grady Booch |access-date=18 August 2014}}</ref> although he did not advocate integrating several times a day. [[Extreme programming]] (XP) adopted the concept of CI and did advocate integrating more than once per day – perhaps as many as tens of times per day.<ref>{{Cite journal |last=Beck |first=K. |date=1999 |title=Embracing change with extreme programming |journal=Computer |volume=32 |issue=10 |pages=70–77 |doi=10.1109/2.796139 |issn=0018-9162}}</ref>
 
'''Continuous integration''' ('''CI''') is the practice of integrating [[source code]] changes frequently and ensuring that the integrated codebase is in a workable state.
== Rationale ==
 
Typically, developers [[Merge (version control)|merge]] changes to an [[Branching (revision control)|integration branch]], and an automated system [[Software build|builds]] and [[software testing|tests]] the [[software system]].<ref name="martinfowler" />
When embarking on a change, a [[software developer|developer]] takes a copy of the current [[code base]] on which to work. As other developers submit changed code to the [[source code repository]], this copy gradually ceases to reflect the repository code. Not only can the existing code base change, but new code can be added as well as new libraries, and other resources that create dependencies, and potential conflicts.
Often, the automated process runs on each [[Commit (version control)|commit]] or runs on a schedule such as once a day.
 
[[Grady Booch]] first proposed the term CI in [[Booch method|1991]],<ref>{{Cite book |last=Booch |first=Grady |url=https://books.google.com/books?id=w5VQAAAAMAAJ&q=continuous+integration+inauthor:grady+inauthor:booch |title=Object Oriented Design: With Applications |publisher=[[Benjamin Cummings]] |year=1991 |isbn=9780805300918 |page=209 |author-link=Grady Booch |access-date=18 August 2014}}</ref> although he did not advocate integrating multiple times a day, but later, CI came to include that aspect.<ref>{{Cite journal |last=Beck |first=K. |date=1999 |title=Embracing change with extreme programming |journal=Computer |volume=32 |issue=10 |pages=70–77 |doi=10.1109/2.796139 |issn=0018-9162}}</ref>
The longer development continues on a branch without merging back to the mainline, the greater the risk of multiple integration conflicts<ref>{{Cite book |last=Duvall |first=Paul M. |title=Continuous Integration. Improving Software Quality and Reducing Risk |publisher=Addison-Wesley |year=2007 |isbn=978-0-321-33638-5}}</ref> 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.
 
== History ==
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",<ref name="Cunningham, Integration Hell">{{Cite web |title=Integration Hell |url=http://c2.com/cgi/wiki?IntegrationHell |last=Cunningham |first=Ward |author-link=Ward Cunningham |date=5 August 2009 |website=WikiWikiWeb |access-date=19 September 2009}}</ref> where the time it takes to integrate exceeds the time it took to make their original changes.<ref>{{Cite web |title=What is Continuous Integration? |url=https://aws.amazon.com/devops/continuous-integration/ |website=Amazon Web Services}}</ref>
{{expand section|date=August 2014}}
 
The earliest known work (1989) on continuous integration was the Infuse environment developed by G. E. Kaiser, D. E. Perry, and W. M. Schell.<ref>{{Cite conference |last1=Kaiser |first1=G. E. |last2=Perry |first2=D. E. |last3=Schell |first3=W. M. |year=1989 |title=Infuse: fusing integration test management with change management |conference=Proceedings of the Thirteenth Annual International Computer Software & Applications Conference |___location=Orlando, Florida |pages=552–558 |doi=10.1109/CMPSAC.1989.65147|citeseerx=10.1.1.101.3770 }}</ref>
== Workflows ==
 
In 1994, Grady Booch used the phrase continuous integration in ''Object-Oriented Analysis and Design with Applications'' (2nd edition)<ref>{{Cite book |last=Booch |first=Grady |url=http://www.cvauni.edu.vn/imgupload_dinhkem/file/pttkht/object-oriented-analysis-and-design-with-applications-2nd-edition.pdf |title=Object-Oriented Analysis and Design with applications |date=December 1998 |edition=2nd |access-date=2 December 2014 |archive-date=19 August 2019 |archive-url=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 |url-status=dead }}</ref> 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".
=== Run tests locally ===
 
In 1997, [[Kent Beck]] and [[Ron Jeffries]] invented [[extreme programming]] (XP) while on the [[Chrysler Comprehensive Compensation System]] project, including continuous integration.<ref name="martinfowler">{{Cite web |title=Continuous Integration |url=http://martinfowler.com/articles/continuousIntegration.html |last=Fowler |first=Martin |date=1 May 2006 |access-date=9 January 2014}}</ref>{{self-published source|date=May 2020}} Beck published about continuous integration in 1998, emphasising the importance of face-to-face communication over technological support.<ref>{{Cite conference |last=Beck |first=Kent |date=28 March 1998 |title=Extreme Programming: A Humanistic Discipline of Software Development |url=https://books.google.com/books?id=YBC5xD08NREC&q=%22Extreme+Programming%3A+A+Humanistic+Discipline+of+Software+Development%22&pg=PA4 |___location=Lisbon, Portugal |publisher=[[Springer Science+Business Media|Springer]] |volume=1 |pages=4 |isbn=9783540643036 |book-title=Fundamental Approaches to Software Engineering: First International Conference}}</ref> In 1999, Beck elaborated more in his first full book on Extreme Programming.<ref name="Beck, Extreme Programming Explained">{{Cite book |last=Beck |first=Kent |url=https://archive.org/details/extremeprogrammi00beck |title=Extreme Programming Explained |publisher=Addison-Wesley Professional |year=1999 |isbn=978-0-201-61641-5 |page=[https://archive.org/details/extremeprogrammi00beck/page/97 97] |ref=Beck, Extreme Programming Explained |author-link=Kent Beck |url-access=registration}}</ref> [[CruiseControl]], one of the first open-source CI tools,<ref>{{Cite news |date=1 February 2018 |title=A Brief History of DevOps, Part III: Automated Testing and Continuous Integration |work=CircleCI |url=https://circleci.com/blog/a-brief-history-of-devops-part-iii-automated-testing-and-continuous-integration/ |access-date=19 May 2018}}</ref>{{self-published source|date=May 2020}} was released in 2001.
CI should be used in combination with automated unit tests written through the practices of [[test-driven development]]. All unit tests in the developer's local [[Deployment environment|environment]] should be run and passed before committing to the mainline. This helps prevent one developer's work-in-progress from breaking another developer's copy. Where necessary, incomplete features can be disabled before committing, using [[feature toggle]]s, for instance.
 
In 2010, Timothy Fitz published an article detailing how [[IMVU]]'s engineering team had built and been using the first practical CD system. While his post was originally met with skepticism, it quickly caught on and found widespread adoption<ref>{{Citation | chapter=A Brief Survey of Current Software Engineering Practices in Continuous Integration and Automated Accessibility Testing | doi=10.1109/WiSPNET51692.2021.9419464| arxiv=2103.00097| s2cid=232076320| title=2021 Sixth International Conference on Wireless Communications, Signal Processing and Networking (WiSPNET)| year=2021| last1=Sane| first1=Parth| pages=130–134| isbn=978-1-6654-4086-8}}</ref> as part of the [[lean software development]] methodology, also based on IMVU.
=== Compile the mainline periodically; run tests of the mainline and/or use continuous quality control ===
 
== Practices ==
A build server compiles the code periodically. The build server may automatically run tests and/or implement other ''continuous'' [[quality control]] processes. Such processes aim to improve [[software quality]] and delivery time by periodically running additional static analyses, measuring performance, extracting documentation from the source code, and facilitating manual [[Quality assurance|QA]] processes. On the popular [[Travis CI]] service for open-source, only 58.64% of CI jobs execute tests.<ref>{{Cite journal |last1=Durieux |first1=Thomas |last2=Abreu |first2=Rui |last3=Monperrus |first3=Martin |last4=Bissyande |first4=Tegawende F. |last5=Cruz |first5=Luis |date=2019 |title=An Analysis of 35+ Million Jobs of Travis CI |journal=2019 IEEE International Conference on Software Maintenance and Evolution (ICSME) |publisher=IEEE |pages=291–295 |arxiv=1904.09416 |bibcode=2019arXiv190409416D |doi=10.1109/ICSME.2019.00044 |isbn=978-1-7281-3094-1 |s2cid=203593737}}</ref>
 
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.
=== Use CI as part of continuous delivery or continuous deployment ===
 
Typically, a [[Server (computing)|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<ref>{{Cite web |title=Continuous integration |url=https://www.atlassian.com/agile/continuous-integration |last=Radigan |first=Dan |website=Atlassian Agile Coach}}</ref> and collect [[software quality]] metrics via processes such as static analysis and performance testing.
CI is often intertwined with [[continuous delivery]] or [[continuous deployment]] in what is called a CI/CD pipeline. "Continuous delivery" ensures the software checked in on the mainline is always in a state that can be deployed to users, while "continuous deployment" fully automates the deployment process.
 
== HistoryRelated practices ==
{{expand howto|section|date=AugustMay 20142015}}
 
This section lists [[best practice]]s from practitioners for other practices that enhance CI.
The earliest known work on continuous integration was the Infuse environment developed by G. E. Kaiser, D. E. Perry, and W. M. Schell.<ref>{{Cite conference |last1=Kaiser |first1=G. E. |last2=Perry |first2=D. E. |last3=Schell |first3=W. M. |year=1989 |title=Infuse: fusing integration test management with change management |conference=Proceedings of the Thirteenth Annual International Computer Software & Applications Conference |___location=Orlando, Florida |pages=552–558 |doi=10.1109/CMPSAC.1989.65147}}</ref>
 
=== Build automation ===
In 1994, Grady Booch used the phrase continuous integration in ''Object-Oriented Analysis and Design with Applications'' (2nd edition)<ref>{{Cite book |last=Booch |first=Grady |url=http://www.cvauni.edu.vn/imgupload_dinhkem/file/pttkht/object-oriented-analysis-and-design-with-applications-2nd-edition.pdf |title=Object-Oriented Analysis and Design with applications |date=December 1998 |edition=2nd |access-date=2 December 2014}}</ref> 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".
{{Main|Build automation}}
 
[[Build automation]] is a best practice.<ref name="Brauneis, [OSLC] Possible new Working Group - Automation">{{Cite mailing list |last=Brauneis |first=David |title=[OSLC] Possible new Working Group – Automation |mailing-list=open-services.net Community |date=1 January 2010 |url=http://open-services.net/pipermail/community_open-services.net/2010-January/000214.html |access-date=16 February 2010 |archive-url=https://web.archive.org/web/20180901173720/http://open-services.net/pipermail/community_open-services.net/2010-January/000214.html |archive-date=1 September 2018 |url-status=dead}}</ref><ref name="Taylor, Rails Deployment and Automation with ShadowPuppet and Capistrano">{{Cite web |last=Taylor |first=Bradley |title=Rails Deployment and Automation with ShadowPuppet and Capistrano |url=http://blog.railsmachine.com/articles/2009/02/10/rails-deployment-and-automation-with-shadowpuppet-and-capistrano/ |url-status=dead |archive-url=https://archive.today/20121202054105/http://blog.railsmachine.com/articles/2009/02/10/rails-deployment-and-automation-with-shadowpuppet-and-capistrano/ |archive-date=2 December 2012 |access-date=16 February 2010 |website=Rails machine |type=[[World Wide Web|blog]] |ref=Taylor, Rails Deployment and Automation with ShadowPuppet and Capistrano}}</ref> [[List of build automation software|Build automation tools]] automate building.
In 1997, [[Kent Beck]] and [[Ron Jeffries]] invented [[Extreme Programming]] (XP) while on the [[Chrysler Comprehensive Compensation System]] project, including continuous integration.<ref name="martinfowler">{{Cite web |title=Continuous Integration |url=http://martinfowler.com/articles/continuousIntegration.html |last=Fowler |first=Martin |date=1 May 2006 |access-date=9 January 2014}}</ref>{{self-published source|date=May 2020}} Beck published about continuous integration in 1998, emphasising the importance of face-to-face communication over technological support.<ref>{{Cite conference |last=Beck |first=Kent |date=28 March 1998 |title=Extreme Programming: A Humanistic Discipline of Software Development |url=https://books.google.com/books?id=YBC5xD08NREC&q=%22Extreme+Programming%3A+A+Humanistic+Discipline+of+Software+Development%22&pg=PA4 |___location=Lisbon, Portugal |publisher=[[Springer Science+Business Media|Springer]] |volume=1 |pages=4 |isbn=9783540643036 |book-title=Fundamental Approaches to Software Engineering: First International Conference}}</ref> In 1999, Beck elaborated more in his first full book on Extreme Programming.<ref name="Beck, Extreme Programming Explained">{{Cite book |last=Beck |first=Kent |url=https://archive.org/details/extremeprogrammi00beck |title=Extreme Programming Explained |publisher=Addison-Wesley Professional |year=1999 |isbn=978-0-201-61641-5 |page=[https://archive.org/details/extremeprogrammi00beck/page/97 97] |ref=Beck, Extreme Programming Explained |author-link=Kent Beck |url-access=registration}}</ref> [[CruiseControl]], one of the first open-source CI tools,<ref>{{Cite news |date=1 February 2018 |title=A Brief History of DevOps, Part III: Automated Testing and Continuous Integration |work=CircleCI |url=https://circleci.com/blog/a-brief-history-of-devops-part-iii-automated-testing-and-continuous-integration/ |access-date=19 May 2018}}</ref>{{self-published source|date=May 2020}} was released in 2001.
 
Proponents of CI recommend that a single command should have the capability of building the system.
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 scepticism, it quickly caught on and found widespread adoption<ref>{{Citation | chapter=A Brief Survey of Current Software Engineering Practices in Continuous Integration and Automated Accessibility Testing | doi=10.1109/WiSPNET51692.2021.9419464| arxiv=2103.00097| s2cid=232076320| chapter-url=https://ieeexplore.ieee.org/document/9419464| title=2021 Sixth International Conference on Wireless Communications, Signal Processing and Networking (WiSPNET)| year=2021| last1=Sane| first1=Parth| pages=130–134| isbn=978-1-6654-4086-8}}</ref> as part of the [[Lean software development]] methodology, also based on IMVU.
 
Automation often includes automating the integration, which often includes [[software deployment|deployment]] into a production-like [[Deployment environment|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 (file format)|DEB]], Red Hat [[RPM Package Manager|RPM]] or Windows [[Microsoft Installer|MSI]] files).
== Common practices ==
{{howto|section|date=May 2015}}
This section lists [[best practice]]s suggested by various authors on how to achieve continuous integration, and how to automate this practice. [[Build automation]] is a best practice itself.<ref name="Brauneis, [OSLC] Possible new Working Group - Automation">{{Cite mailing list |url=http://open-services.net/pipermail/community_open-services.net/2010-January/000214.html |title=[OSLC] Possible new Working Group – Automation |date=1 January 2010 |last=Brauneis |first=David |mailing-list=open-services.net Community |access-date=16 February 2010 |archive-url=https://web.archive.org/web/20180901173720/http://open-services.net/pipermail/community_open-services.net/2010-January/000214.html |archive-date=1 September 2018 |url-status=dead }}</ref><ref name="Taylor, Rails Deployment and Automation with ShadowPuppet and Capistrano">{{Cite web |title=Rails Deployment and Automation with ShadowPuppet and Capistrano |url=http://blog.railsmachine.com/articles/2009/02/10/rails-deployment-and-automation-with-shadowpuppet-and-capistrano/ |last=Taylor |first=Bradley |website=Rails machine |type=[[World Wide Web|blog]] |url-status=dead |archive-url=https://archive.today/20121202054105/http://blog.railsmachine.com/articles/2009/02/10/rails-deployment-and-automation-with-shadowpuppet-and-capistrano/ |archive-date=2 December 2012 |access-date=16 February 2010 |ref=Taylor, Rails Deployment and Automation with ShadowPuppet and Capistrano}}</ref>
 
=== Atomic commits ===
Continuous integration—the practice of frequently integrating one's new or changed code with the existing code repository —should occur frequently enough that no intervening window remains between [[Commit (version control)|commit]] and [[Software build|build]], and such that no errors can arise without developers noticing them and correcting them immediately.<ref name="martinfowler" /> Normal practice is to trigger these builds by every commit to a repository, rather than a periodically scheduled build. The practicalities of doing this in a multi-developer environment of rapid commits are such that it is usual to trigger a short time after each commit, then to start a build when either this timer expires or after a rather longer interval since the last build. Note that since each new commit resets the timer used for the short time trigger, this is the same technique used in many button debouncing algorithms.<ref>See for example {{Cite web |title=Debounce |url=https://www.arduino.cc/en/Tutorial/Debounce |date=29 July 2015 |website=Arduino}}</ref> In this way, the commit events are "debounced" to prevent unnecessary builds between a series of rapid-fire commits. Many automated tools offer this scheduling automatically.
 
AnotherCI factor isrequires the need for a version control system thatto supportssupport [[atomic commit]]s; i.e., all of a developer's changes mayare be seenhandled as a single commit operation. There is no point in trying to build from only half of the changed files.
 
=== Committing changes ===
To achieve these objectives, continuous integration relies on the following principles.
 
When making a code change, a [[software developer|developer]] creates a branch that is a copy of the current [[codebase]]. As other changes are committed to the [[source code repository|repository]], this copy diverges from the latest version.
=== Maintain a code repository ===
{{Main|Version control}}
 
The longer development continues on a branch without merging to the integration branch, the greater the risk of multiple integration conflicts<ref>{{Cite book |last=Duvall |first=Paul M. |title=Continuous Integration. Improving Software Quality and Reducing Risk |publisher=Addison-Wesley |year=2007 |isbn=978-0-321-33638-5}}</ref> 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.
This practice advocates the use of a revision control system for the project's source code. All artifacts required to build the project should be placed in the repository. In this practice and the revision control community, the convention is that the system should be buildable from a fresh checkout and not require additional dependencies. [[Extreme Programming]] advocate [[Martin Fowler (software engineer)|Martin Fowler]] also mentions that where [[branching (software)|branching]] is supported by tools, its use should be minimised.<ref name="Fowler, Continuous Integration practices">{{Cite web |title=Practices |url=http://martinfowler.com/articles/continuousIntegration.html#PracticesOfContinuousIntegration |last=Fowler |first=Martin |author-link=Martin Fowler (software engineer) |website=Continuous Integration |type=article |access-date=29 November 2015}}</ref> Instead, it is preferred for changes to be integrated rather than for multiple versions of the software to be maintained simultaneously. The mainline (or [[trunk (software)|trunk]]) should be the place for the working version of the software.
 
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",<ref name="Cunningham, Integration Hell">{{Cite web |title=Integration Hell |url=http://c2.com/cgi/wiki?IntegrationHell |last=Cunningham |first=Ward |author-link=Ward Cunningham |date=5 August 2009 |website=WikiWikiWeb |access-date=19 September 2009}}</ref> where the time it takes to integrate exceeds the time it took to make their original changes.<ref>{{Cite web |title=What is Continuous Integration? |url=https://aws.amazon.com/devops/continuous-integration/ |website=Amazon Web Services}}</ref>
=== Automate the build ===
{{Main|Build automation}}
 
=== Testing locally ===
A single command should have the capability of building the system. Many build tools, such as [[make (software)|make]], have existed for many years. [[List of build automation software|Other more recent tools]] are frequently used in continuous integration environments. Automation of the build should include automating the integration, which often includes [[software deployment|deployment]] into a production-like [[Deployment environment|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 (file format)|DEB]], Red Hat [[RPM Package Manager|RPM]] or Windows [[Microsoft Installer|MSI]] files).
 
Proponents of CI suggest that developers should
=== Make the build self-testing ===
use [[test-driven development]] and to
ensure that all [[unit testing|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 toggle]]s.
Once the code is built, all tests should run to confirm that it behaves as the developers expect it to behave.<ref>{{Cite web |title=Continuous integration |url=https://www.atlassian.com/agile/continuous-integration |last=Radigan |first=Dan |website=Atlassian Agile Coach}}</ref>
 
=== Continuous delivery and continuous deployment ===
=== Everyone commits to the baseline every day ===
{{See also|CI/CD}}
 
[[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.
By committing regularly, every committer can reduce the number of conflicting changes. Checking in a week's worth of work runs the risk of conflicting with other features and can be very difficult to resolve. Early, small conflicts in an area of the system cause team members to communicate about the change they are making.<ref name=":0">{{Cite web |title=Continuous Integration |url=https://www.thoughtworks.com/continuous-integration |website=Thoughtworks}}</ref> Committing all changes at least once a day (once per feature built) is generally considered part of the definition of Continuous Integration. In addition, performing a [[nightly build]] is generally recommended.{{Citation needed|date =April 2012}} These are lower bounds; the typical frequency is expected to be much higher.
 
''Continuous delivery'' and ''continuous deployment'' are often performed in conjunction with CI and together form a CI/CD pipeline.
=== Every commit (to baseline) should be built ===
 
=== Version control ===
{{Main|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 (software engineer)|Martin Fowler]] recommends that all developers commit to the same integration branch.<ref name="Fowler, Continuous Integration practices">{{Cite web |title=Practices |url=http://martinfowler.com/articles/continuousIntegration.html#PracticesOfContinuousIntegration |last=Fowler |first=Martin |author-link=Martin Fowler (software engineer) |website=Continuous Integration |type=article |access-date=29 November 2015}}</ref>
=== 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.<ref>{{cite book
|title=Continuous Integration: Improving Software Quality and Reducing Risk
|author1=Paul M. Duvall
|author2=Steve Matyas
|author3=[[Andrew Glover]]
|isbn=978-0-321-33638-5
|publisher=[[Addison-Wesley Professional]]
|date=2007
}}</ref>
 
===Daily build===
 
[[daily build|Building daily]], if not more often, is generally recommended.{{Citation needed|date =April 2012}}
 
=== 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 (computer software)|daemon]] to monitor the [[revision control|revision control system]] for changes, then automatically run the build process.
Line 73 ⟶ 99:
=== 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 testing|regression]]. Researchers have proposed to automate this task: if a bug-fix commit does not contain a test case, it can be generated from the already existing tests.<ref>{{Cite journal |last1=Danglot |first1=Benjamin |last2=Monperrus |first2=Martin |last3=Rudametkin |first3=Walter |last4=Baudry |first4=Benoit |date=5 March 2020 |title=An approach and benchmark to detect behavioral changes of commits in continuous integration |journal=Empirical Software Engineering |volume=25 |issue=4 |pages=2379–2415 |language=en |arxiv=1902.08482 |doi=10.1007/s10664-019-09794-7 |s2cid=67856113 |issn=1382-3256}}</ref>
 
=== Keep the build fast ===
Line 97 ⟶ 123:
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.<ref>{{Cite web |title=Continuous deployment in 5 easy steps |url=http://radar.oreilly.com/2009/03/continuous-deployment-5-eas.html |last=Ries |first=Eric |date=30 March 2009 |website=Radar |publisher=O’Reilly |access-date=10 January 2013}}</ref><ref>{{Cite web |title=Continuous Deployment at IMVU: Doing the impossible fifty times a day |url=http://timothyfitz.wordpress.com/2009/02/10/continuous-deployment-at-imvu-doing-the-impossible-fifty-times-a-day/ |last=Fitz |first=Timothy |date=10 February 2009 |publisher=Wordpress |access-date=10 January 2013}}</ref>
 
== Costs and benefitsBenefits ==
{{POV section|date=May 2016}}
{{More citations needed section|date=May 2016}}
 
CI benefits include:
Continuous integration is intended to produce benefits such as:
 
* Facilitates detecting [[software bug|bugs]] earlier
* Reduces effort to find cause of bugs; if a CI test fails then changes since last good build contain causing change; if build after each change then exactly one change is the cause<ref name="martinfowler" />
* Avoids the chaos of integrating many changes
* When a test fails or a bug is found, reverting the codebase to a good state results in fewer lost changes
* Frequent availability of a known-good build for testing, demo, and release
* Frequent code commit encourages modular, less complex code<ref>{{Cite journal |last1=Junpeng |first1=Jiang |last2=Zhu |first2=Can |last3=Zhang |first3=Xiaofang |date=July 2020 |title=An Empirical Study on the Impact of Code Contributor on Code Smell |url=https://qrs20.techconf.org/download/QRS-IJPE/12_An%20Empirical%20Study%20on%20the%20Impact%20of%20Code%20Contributor%20on%20Code%20Smell.pdf |journal=International Journal of Performability Engineering |volume=16 |issue=7 |pages=1067–1077 |doi=10.23940/ijpe.20.07.p9.10671077|s2cid=222588815 }}</ref>
* Quick feedback on system-wide impact of code changes
* Supports collection of [[software metrics]] such as [[code coverage]], [[code complexity]]
 
== Risks ==
 
Risks of CI include:
 
* [[Build system]] setup requires effort<ref>{{Cite journal |last=Laukkanen |first=Eero |year=2016 |title=Problems, causes and solutions when adopting continuous delivery—A systematic literature review |journal=Information and Software Technology |volume=82 |pages=55–79 |doi=10.1016/j.infsof.2016.10.001 |doi-access=free}}</ref>
* Writing and maintaining an automated test suite requires effort
* Value added depends on the quality of tests<ref name=":1">{{Cite web |title=Assessing challenges of continuous integration in the context of software requirements breakdown: a case study |url=http://publications.lib.chalmers.se/records/fulltext/220573/220573.pdf |last=Debbiche |first=Adam}}</ref>
* High build latency (sitting in queue) limits value<ref name=":1" />
* Implies that incomplete code should not be integrated which is counter to some developer's preferred practice<ref name=":1" />
* Safety and mission-critical development assurance (e.g., [[DO-178C]], [[ISO 26262]]) require documentation and review which may be difficult to achieve
 
== Best practices for cloud systems ==
* [[Software testing#Integration testing|Integration bugs]] are detected early and are easy to track down due to small changesets. This saves both time and money over the lifespan of a project.
The following practices can enhance productivity of [[CI/CD|pipelines]], especially in systems hosted in the [[Cloud computing|cloud]]: <ref>{{Cite book |title=Serverless Architectures on AWS |date=29 March 2022 |publisher=Manning |isbn=978-1617295423}}</ref><ref>{{Cite book |title=Pipeline as Code Continuous Delivery with Jenkins, Kubernetes, and Terraform |date=23 November 2021 |publisher=Manning |isbn=9781638350378}}</ref><ref>{{Cite book |title=Continuous Delivery Reliable Software Releases Through Build, Test, and Deployment Automation |isbn=9780321670229 |last1=Humble |first1=Jez |last2=Farley |first2=David |date=27 July 2010 |publisher=Pearson Education }}</ref>
* Avoids last-minute chaos at release dates, when everyone tries to check in their slightly incompatible versions
* When unit tests fail or a [[Software bug|bug]] emerges, if developers need to revert the codebase to a bug-free state without [[debugging]], only a small number of changes are lost (because integration happens frequently)
* Constant availability of a "current" build for testing, demo, or release purposes
* Frequent code check-in pushes developers to create modular, less complex code{{Citation needed|date= November 2009}}
 
* '''Number of Pipelines''': Small teams can be more productive by having one [[Repository (version control)|repository]] and one pipeline. In contrast, larger organizations may have separate repositories and pipelines for each team or even separate repositories and pipelines for each service within a team.
With continuous automated testing, benefits can include:
* '''Permissions''': In the context of [[CI/CD|pipeline-related]] permissions, adhering to the [[principle of least privilege]] can be challenging due to the dynamic nature of [[Software architecture|architecture]]. Administrators may opt for more permissive permissions while implementing compensating [[security controls]] to minimize the blast radius.
* Enforces discipline of frequent automated testing
* Immediate feedback on the system-wide impact of local changes
* [[Software metrics]] generated from automated testing and CI (such as metrics for [[code coverage]], [[code complexity]], and [[feature complete]]ness) focus developers on developing functional, quality code, and help develop momentum in a team{{Citation needed|date=November 2009}}
Some downsides of continuous integration can include:
* Constructing an automated test suite requires a considerable amount of work, including ongoing effort to cover new features and follow intentional code modifications.
** [[Software testing|Testing]] is considered a [[best coding practices|best practice for software development]] in its own right, regardless of whether or not continuous integration is employed, and automation is an integral part of project methodologies like [[test-driven development]].
** Continuous integration can be performed without any test suite, but the cost of [[quality assurance]] to produce a releasable product can be high if it must be done manually and frequently.
* There is some work involved to set up a [[build system]], and it can become complex, making it difficult to modify flexibly.<ref>{{Cite journal |last=Laukkanen |first=Eero |year=2016 |title=Problems, causes and solutions when adopting continuous delivery—A systematic literature review |journal=Information and Software Technology |volume=82 |pages=55–79 |doi=10.1016/j.infsof.2016.10.001 |doi-access=free}}</ref>
** However, there are a number of [[Comparison of continuous integration software|continuous integration software projects]], both proprietary and open-source, which can be used.
* Continuous integration is not necessarily valuable if the scope of the project is small or contains untestable legacy code.
* Value added depends on the quality of tests and how testable the code really is.<ref name=":1">{{Cite web |title=Assessing challenges of continuous integration in the context of software requirements breakdown: a case study |url=http://publications.lib.chalmers.se/records/fulltext/220573/220573.pdf |last=Debbiche |first=Adam}}</ref>
* Larger teams mean that new code is constantly added to the integration queue, so tracking deliveries (while preserving quality) is difficult and builds queueing up can slow down everyone.<ref name=":1" />
* With multiple commits and merges a day, partial code for a feature could easily be pushed and therefore integration tests will fail until the feature is complete.<ref name=":1" />
* Safety and mission-critical development assurance (e.g., [[DO-178C]], [[ISO 26262]]) require rigorous documentation and in-process review that are difficult to achieve using continuous integration. This type of life cycle often requires additional steps to be completed prior to product release when regulatory approval of the product is required.
 
== See also ==
* [[{{Annotated link|Application release automation]]}}
* [[{{Annotated link|Build light indicator]]}}
* [[{{Annotated link|Comparison of continuous integration software]]}}
* [[{{Annotated link|Continuous design]]}}
* [[{{Annotated link|Continuous testing]]}}
* [[{{Annotated link|Multi-stage continuous integration]]}}
* [[{{Annotated link|Rapid application development]]}}
 
== References ==
Line 142 ⟶ 171:
* {{Cite web |title=A Recipe for Build Maintainability and Reusability |url=http://jayflowers.com/joomla/index.php?option=com_content&task=view&id=26 |last=Flowers |first=Jay |access-date=28 May 2006 |archive-date=25 June 2020 |archive-url=https://web.archive.org/web/20200625060704/https://jayflowers.com/joomla/index.php?option=com_content&task=view&id=26 |url-status=dead }}
* {{Cite web |title=Developer works |url=http://www.ibm.com/developerworks/java/library/j-ap11297/ |last=Duvall |first=Paul |website=[[IBM]] |date=4 December 2007}}
* {{Cite web |title=Version lifecycle |date=June 2024 |url=http://www.mediawiki.org/wiki/Version_lifecycle |publisher=MediaWiki}}
 
[[Category:Continuous integration| ]]