Continuous integration (CI) is the practice of merging all developer workspaces with a shared mainline.
It was first named and proposed as part of extreme programming (XP). Its main aim is to prevent integration problems.
Problem
When embarking on a change, a 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.
The longer a branch of code remains checked out, the greater the risk of multiple integration conflicts and failures becomes when it is reintegrated into the main line. 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.
In a worst-case scenario, developers may have to discard their changes and completely redo the work.
CI as a solution
The practice aims to reduce rework and thus reduce cost and time.
A complementary practice to CI is that before submitting work, each programmer must do a complete build and run (and pass) all unit tests. Integration tests are usually run automatically on a CI server when it detects a new commit. All programmers should start the day by updating the project from the repository. That way, they will all stay up-to-date.
Principles
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 and build, and such that no errors can arise without developers noticing them and correcting them immediately.
Automated tools such as CruiseControl, Jenkins, Hudson, Bamboo, BuildMaster, AnthillPro or Teamcity offer this scheduling automatically.
Another factor is the need for a version control system that supports atomic commits, i.e. all of a developer's changes may be seen as a single commit operation.
Continuous integration relies on the following principles :
1. Maintain a code repository
- 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.
- System should be buildable from a fresh checkout and not require additional dependencies.
- The mainline (or trunk) should be the place for the working version of the software.
2. Automate the build
- A single command should have the capability of building the system.
- Tools like Ant, Maven, Gradle, MSBuild, OpenMake Meister or IBM Rational Build Forge are frequently used in continuous integration environments.
- The build script not only compiles binaries, but also generates documentation, website pages, statistics and distribution media.
3. Make the build self-testing
- Once the code is built, all tests should run to confirm that it behaves as the developers expect it to behave.
4. Everyone commits to the baseline every day
- By committing regularly, every committer can reduce the number of conflicting changes.
- In addition performing a nightly build is generally recommended.
5. Every commit (to baseline) should be built
- The system should build commits to the current working version in order to verify that they integrate correctly.
- Automated Continuous Integration can be used where a continuous integration server or daemon monitors the version control system for changes, then automatically runs the build process.
6. Keep the build fast
- The build needs to complete rapidly, so that if there is a problem with integration, it is quickly identified.
7. 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.
- Building a replica of a production environment is cost prohibitive.
8. 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.
- Finding errors earlier also, in some cases, reduces the amount of work necessary to resolve them.
9. 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.
10. Automate deployment
- Most CI systems allow the running of scripts after a build finishes.
Advantages of Continuous integration
- When unit tests fail or a bug emerges, developers might revert the codebase to a bug-free state, without wasting time debugging.
- Developers detect and fix integration problems continuously — avoiding last-minute changes at release dates.
- Early warning of broken/incompatible code
- Early warning of conflicting changes
- Immediate unit testing of all changes
- Constant availability of a "current" build for testing, demo, or release purposes
- Immediate feedback to developers on the quality, functionality, or system-wide impact of code they are writing
- Frequent code check-in pushes developers to create modular, less complex code
Disadvantages
- Initial setup time required
- Well-developed test-suite required to achieve automated testing advantages
No comments:
Post a Comment
Note: only a member of this blog may post a comment.