Continuous Integration - Continuous Integration Practices
Continuous integration is a software engineering practice of merging all developers’ working copies to a shared mainline several times a day. The term originates from a best practice of extreme programming, whose main purpose is to prevent the accumulation of integration problems. Continuous integration can be seen as the regular-integration practice advocated by early iterative, incremental development. [1]
Principles
Single source repository: project source code is stored in a single version control system, so everyone can get the latest source code from there. Continuous integration encourages developers to commit modified source code frequently. The system can always be built from the latest checkout, with no extra dependencies needed, fewer branches, and integration used instead of maintaining multiple software versions.
Automated build: a single command can build the system. Automated builds include automated integration and automated deployment. In many cases, the build script not only compiles binaries but also generates documentation, web pages, statistics, and distribution media.
Automated testing: once the code builds, all tests run automatically to confirm expectations are met.
Everyone commits to the mainline every day: through regular commits, each committer can reduce conflicts caused by code changes. In the traditional development model, integration and testing only happen after development reaches a certain stage, but many bugs already exist early in the project; if they’re only discovered at final integration, developers need to spend a lot of time during integration locating the bug. But if checked early, a small subset of conflicts in the system lets team members communicate sooner. It’s recommended to commit all changes at least once a day and run automated build and test verification, to catch integration errors as early as possible. For continuous integration, the more frequent the integration, the better the results.
Every commit should be buildable: to verify correct integration, every commit to the current working version should be buildable. The continuous integration server monitors the version control system, and a build runs automatically whenever there’s a change.
Keep the build fast
Test in a copy of the production environment: deploying to production can fail even after passing a test environment, because production and test environments often differ in many ways.
Make it easy to get the latest deliverable
Everyone can see the results of the latest version
Automated deployment: many continuous integration systems allow scripts to run after a build completes, releasing the system to a test environment so everyone can see the results. This can be extended further to automate deployment to production.
Integration Process
Developer checks out the latest code from the source repository
Developer writes code and test cases, then commits the updated results to the version control repository
Based on trigger conditions, the continuous integration server checks out the latest code from the version control repository, compiles it, runs tests, packages it, and if necessary deploys and releases the product
Developer reviews any problems that occurred during integration
Benefits
Easy to pinpoint errors. That is, when your continuous integration fails, it means the code you just added or modified caused the error, so you can easily tell who made the mistake
Achieve system-level results early in the project. Because the code has already been integrated, even if the whole system isn’t fully usable yet, at least you and your team can already see that it’s there
Improved control over progress. This is quite obvious — every day you can see which features are usable and which are not yet implemented
More thoroughly test each unit within the system
Build the whole system in less time
Helps with collecting project development data
Continuous code quality improvement combined with other tools
Continuous testing combined with test tools or frameworks
Facilitates code review
Facilitates management of the development process
References