How to put CI, CT and CD together in a DevOps pipeline
DevOps pipelines aren't just about CI/CD. Learn why continuous testing is a crucial piece of the puzzle and how it ultimately results in cleaner code with fewer errors.
Continuous integration, continuous testing and continuous delivery accelerate software delivery workflows and the code release process, making them foundational to DevOps.
These processes together are often referred to as a CI/CD pipeline or DevOps pipeline, which omits CT from the description, despite its importance in the approach. Learn how to combine continuous integration, testing and delivery to ensure faster, less error-prone software releases.
What is CI in DevOps?
CI is a software development practice that involves automatically integrating code from multiple developers into a secure and centralized repository, such as GitHub or GitLab. CI merges code changes frequently into the repository -- often multiple times a day.
Slack and Microsoft Teams often integrate with CI tools to provide real-time updates to a development team and facilitate quick responses to any issues that arise during deployment.
What is CT in DevOps?
CT involves executing tests at every stage of the development lifecycle.
Once a developer commits code to a repo, CT begins to shine. Automated tests fire off, ensuring that aspects of the codebase function correctly before the code moves on to the next stage. With test automation, developers can catch issues early in the development process before deployment.
CT ensures that testing and validation is an ongoing process throughout the DevOps lifecycle, enabling quick feedback and reducing the time to market.
Continuous testing involves various types of automated tests, including the following:
- Unit.
- Integration.
- Regression.
- Performance.
- Security.
Each type of test targets different aspects of the code and ensures overall code quality and stability.
CT provides a feedback loop to developers, helping them identify and address issues promptly to ensure the delivery of high-quality software. Additionally, it involves tracking and analyzing metrics such as test coverage, test pass-fail rates and code quality to continuously improve the testing process and the codebase.
What is CD in DevOps?
The final phase is CD. In this stage, code becomes executable and deploys into the production environment. DevOps teams often use infrastructure as code (IaC) tools, such as HashiCorp's 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 its dependencies.
Version control is key to a successful CI/CT/CD pipeline. These processes and systems enable the development 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 code defect detection. CI/CT/CD pipelines provide rapid feedback to developers, enabling them to quickly address any issues that arise. This continuous feedback loop leads to faster iterations and a more efficient development cycle for the organization. Feedback comes from tool dashboards or chat tools.
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, technical writers, 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 parts of the codebase that control the release of new application features to a subset of clients. With feature flags, developers 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.
Third-party tools, such as LaunchDarkly, enable developers to release features to targeted users, conduct A/B testing and gradually roll out new features. Flagsmith, an open source feature flagging and remote configuration service, is another option. Flagsmith can be self-hosted or a managed service. Both tools integrate with popular CI/CD offerings.
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 and then commit the code to a central code repository. Organizations often use version control tools, like GitHub and GitLab, for this. These platforms enable developers to write or modify code without interrupting another developer's progress.
The next phase involves the CI server, which triggers tests to run on the code. Teams should 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, kick off the pipeline and move code from successful tests to build automation. Jenkins is the most prolific automation server in the industry; others include 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 in legacy and new code. Teams should use plugins in the CI server to configure static code analysis with a tool such as SonarQube or Codacy. Unit tests are performed after the code passes static tests if they haven't been conducted 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; these tests 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 following is the difference between the two:
- Continuous delivery puts a change in a staging environment and the release schedule, where a person manually approves code and 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 and Google Cloud. With any tool, infrastructure configuration can take some time, depending on the type of resources being deployed. IaC tools provide a repeatable deployment process, often with version-controlled configuration files that developers can modify as needed.
Kubernetes plays a pivotal role in the CD process by providing a scalable and reliable platform for automated application deployments. It orchestrates containerized applications, ensuring seamless updates and rollbacks across distributed systems. By integrating with CI/CD pipelines, Kubernetes streamlines the deployment workflow, enhancing efficiency and reducing downtime.
Teams should also run security scans and vulnerability assessments throughout the pipeline. For instance, static application security testing tools analyze source code and identify vulnerabilities early in the development process. Teams can also use dynamic application security testing during the build phase to simulate attacks on the running application and uncover security flaws. Container image scanning can check for vulnerabilities in containerized environments before deployment.
MLOps and machine learning are also showing increasing promise in all phases of the CI/CT/CD process as vendors seek innovative methods to capture, analyze and present data through the software delivery lifecycle.
CI/CT/CD ultimately provides an automated set of tools and processes that results in safe deployments to production, doing away with manual efforts that take a lot of time to complete and introduce human error. A DevOps pipeline enables development teams to focus on more strategic software delivery tasks, freeing them from unimaginative, rote operations and maintenance tasks.
Michael Levan is a cloud enthusiast, DevOps pro and HashiCorp Ambassador. He speaks internationally, writes blogs, publishes books and creates online courses on various IT topics. He makes real-world, project-focused content to coach engineers on how to create quality work.
Will Kelly is a freelance writer and content strategist who has written about cloud, DevOps, AI and enterprise mobility.