What Should Be Included in a CI Pipeline?
March 26, 2024
In our previous article, we discussed how CI (Continuous Integration) allows multiple developers to work on different features in the same codebase and continuously merge changes into a shared branch. But what exactly happens during this integration process?
Think about your own development workflow. What steps do you take before your code reaches production? Most likely, you don't just write code and immediately deploy it. There's a whole series of checks and validations that happen first.
CI Process Starts After Code Reaches the Remote Branch
Generally, the CI process begins once code is pushed to a remote branch. Modern CI tools automatically run the entire CI pipeline on dedicated servers after detecting new code on the remote branch. But modern software development teams don't just check for merge conflicts - they do much more.
What do you think happens to your code before it gets deployed? Most people's first thought is "Code Review." But before code review, there are many things that can be automatically checked. These automated checks are perfect candidates for your CI pipeline.
Code Formatting Checks
Code formatting checks enforce consistent code style across your team. Tools like Prettier for JavaScript ensure everyone follows the same formatting rules.
Why does this matter? Some engineers prefer two-space indentation, others prefer four spaces. Instead of spending valuable code review time debating formatting preferences, your team can establish standards and let automated tools enforce them. During CI, formatting tools scan your code to ensure it matches your team's established style guidelines.
This might seem trivial, but consistency matters. When everyone's code looks the same, it's easier to read, understand, and maintain.
Static Analysis
Static analysis tools perform automated code analysis, scanning your codebase to ensure it follows team rules and language-specific best practices. For example, TSLint (or its successor ESLint with TypeScript support) checks whether your TypeScript code follows proper TypeScript conventions.
What's powerful about static analysis? It catches issues that developers might miss. Common problems like unused variables, potential null pointer exceptions, or violations of coding standards get flagged automatically. This prevents problematic code from reaching the merge stage.
Automated Testing
Besides the checks above, most teams include automated testing in their CI pipeline. This encompasses unit tests, integration tests, and end-to-end (E2E) tests. If newly pushed code fails any test, the CI tool reports an error and notifies relevant team members.
Why is this crucial? Automated testing ensures your code works correctly before it gets merged. You catch bugs early, when they're cheaper and easier to fix. Imagine discovering a critical bug in production versus catching it during CI - the difference in impact is enormous.
Successful Build Verification
Of course, beyond all these checks, one of the most important CI steps is ensuring your code can be compiled and built successfully. To avoid wasting computational resources, build verification usually happens after all other checks pass.
Why does this matter? Code that can't build can't be deployed. It's that simple. CI catches build failures early, preventing broken code from reaching your deployment pipeline.
Advanced Checks
In the industry, many software development teams add more sophisticated checks to their CI pipelines. Security scans detect potential vulnerabilities before they reach production. Performance tests ensure your code meets minimum performance thresholds.
You can customize your CI pipeline based on your team's specific needs, adding various automated checks to maintain engineering quality standards.
But remember the core purpose of CI: through automation, engineers can push code to remote branches and have all these important checks run automatically, without manual intervention. This streamlines the integration process while maintaining high quality standards.
As you build or improve your team's CI pipeline, start with the fundamentals - formatting, static analysis, testing, and build verification. These four pillars will catch most issues before they reach production. Then gradually add more sophisticated checks based on your specific needs and risk tolerance.
The goal isn't to have the most complex CI pipeline, but rather the most effective one for your team. Every check you add should solve a real problem and provide clear value.
Support ExplainThis
If you found this content helpful, please consider supporting our work with a one-time donation of whatever amount feels right to you through this Buy Me a Coffee page, or share the article with your friends to help us reach more readers.
Creating in-depth technical content takes significant time. Your support helps us continue producing high-quality educational content accessible to everyone.