Continuous integration, continuous testing and continuous delivery accelerate the code release process, and are thus crucial to DevOps. These processes are often referred to as a CI/CD pipeline or a DevOps pipeline, which omits testing from the description, despite its importance in the approach.
Continuous integration (CI) occurs when developers commit their code to a repository, managing updates and fixes with version control. Once the code commits to the repo, continuous testing (CT) begins to shine. Automated tests fire off, which ensure that aspects of the codebase function correctly before the code moves onto the next stage. With test automation, developers can catch issues early in the development process, before deployment.
The final phase is continuous delivery (CD); this stage is where code becomes executable and deploys into the production environment. DevOps teams often use infrastructure as code (IaC) tools, such as HashiCorp Terraform and Packer, to release to production. The organization can also version control the configuration files for the application infrastructure, increasing automation. When ready to deploy a release, the organization tests the code once more and provisions the environment with the latest version of the application and all of its dependencies.
Version control is key to a successful CI/CT/CD pipeline. These processes and systems allow the team to review application and infrastructure configuration code. Thus, version control provides a starting point for the automation server that triggers each step of the pipeline. When the developers or DevOps engineers commit code to a specific branch, that step initiates the entire pipeline.
Benefits of CI/CT/CD pipelines
A CI/CT/CD pipeline provides guardrails against rogue or error-prone changes to the codebase, and early detection of code defects. The pipeline also automates the entire deployment. Manual software deployment is prone to human error. When an organization automates the steps leading up to a release, it can ensure that both the code and deployment process work correctly. When developers, QA engineers, tech support or other team members find a defect, they can rely on the pipeline to automate a rollback to the previous code version.
CI/CT/CD pipelines also enable another safeguard against problems in production: feature flags. Feature flags are part of the codebase that controls the release of new application features to a subset of clients. With feature flags, you can hide functions within the application's source code until the feature is ready for selective or broad use. Feature flags can deploy features in a small subset of users for canary testing. If those users experience any issues, the organization can prevent or roll back the deployment. Feature flags provide unparalleled control over the deployment from the application itself.
How CI/CT/CD works
Let's walk through the sequence of a CI/CT/CD pipeline and common tools therein.
Continuous integration. In the CI stage, developers write a feature, update or fix, then commit the code to a central code repository. Organizations often use version control tools like GitHub and Atlassian Bitbucket. These tools enable developers to write or modify code without interrupting another developer's progress.
The next phase involves the automation server, which triggers tests to run on the code. Configure the automation server to watch when a particular branch in the code repository receives a commit. The server should then pull down the code and kick off the pipeline, move code from successful tests to build automation, and so on. Jenkins is the most prolific automation server in the industry; others include Atlassian Bamboo, CircleCI, Travis CI and CloudBees CI.
Continuous testing. In the initial stage of the pipeline, static code analysis can check for syntax issues and common vulnerabilities. Use plugins in the CI server to configure static code analysis with a tool from the likes of SonarQube, Veracode or Codacy. Static code analysis is an initial test of the code. If the code passes, the unit test stage comes next, unless these tests were performed earlier in the pipeline. Unit tests ensure individual functions perform correctly. The final test stage is functional testing, which comes after the CI server triggers the build. Functional tests make sure that the application or feature does what it is designed to do; they are the gatekeepers before code deploys.
Continuous delivery. Once code passes all the tests, the final stage is deployment. Within the context of a DevOps pipeline, CD often refers to continuous delivery, but it can also mean continuous deployment. The difference between continuous delivery and continuous deployment is:
- Continuous delivery puts a change in a staging environment and the release schedule, where a person manually approves code, then deploys it.
- Continuous deployment automatically deploys code to production once it passes tests.
Not all CI servers natively support CD, but plugins and shell scripts can enable the practice. Tools to automate deployment include Terraform, AWS CloudFormation, Chef, Puppet and Ansible. Terraform supports environment configuration and release onto numerous cloud platforms such as AWS, Azure, Google Cloud Platform and VMware VMs. Whether you use Terraform or another tool, infrastructure configuration can take some time, depending on the type of resources to be deployed. IaC tools provide a repeatable deployment process, often with version controlled configuration files that developers can modify as needed.
The CI/CT/CD process, like the one detailed above, ultimately provides an automated solution that results in safe deployments to production. Rather than endure manual efforts that take a lengthy amount of time to complete, and introduce human error, automate a DevOps pipeline to get more time for important things -- and a little peace of mind.