Slow, flaky builds make you stop trusting CI. The continuous integration best practices that fix this are simple: commit small and often, keep the build fast and green, and test in an environment that mirrors production.
If you want the bigger picture first, read the explainer on what is ci/cd.
| Practice | Guideline |
|---|---|
| Build time | Ten-minute build |
| Commit and share frequency | At least once daily |
| Builds per release | Build once, promote the same artifact |
| Test environment refresh | Between each pipeline run |
| Build trigger | Every commit |
These figures come from GitLab’s CI guide and JetBrains’ TeamCity CI/CD guide. They are guidelines that can change, so check the sources before you rely on them.
Commit small and commit often
The first habit is the one every source agrees on: integrate early. GitLab explains that when a team commits code changes early and often, bugs are easier to identify because there is less code to sort through.
JetBrains sets a practical bar: aim for everyone on the team to commit and share changes at least once daily. Its guide also says all source code, configuration files, scripts and dependencies belong in version control, and that how you use version control counts as much as having it (JetBrains TeamCity guide).
Frequent commits can feel uncomfortable at first, often because of fear of scrutiny or tasks that seem too big for a day. The fix is to split the work. Thoughtworks suggests breaking a feature into smaller, independent tasks, each followed by a commit and check-in, and gives a database-write example (Thoughtworks, February 2022):
- Add a repository layer to write to the database.
- Introduce a new endpoint and connect it to the repository layer.
- Add different error responses for when a write fails.
- Add validation checks for the request body.
Small commits also let you revert one specific task instead of the whole feature. That is much cheaper than untangling a large merge later.
Keep the build fast and green
A slow build quietly taxes every commit. GitLab puts it plainly: nothing slows down a pipeline like complexity, and every minute taken off build times is a minute saved for each developer every time they commit. It points to Martin Fowler’s guideline of a ten-minute build, which it says most modern projects can achieve (GitLab).
JetBrains describes the goal as a constantly releasable codebase, with the team taking collective responsibility for builds. To avoid trivial failures such as syntax mistakes or missing dependencies, it recommends building and running initial tests locally with the same scripts the CI system uses (JetBrains TeamCity guide).
Test order matters too. JetBrains suggests layering your automated tests like this:
- Run the quickest tests first, typically unit tests, to get feedback as early as possible.
- Split tests into batches and run them in parallel for faster results.
- Introduce longer-running tests only once the quicker tests have passed.
- Limit manual quality assurance until after the automated tests have completed.
You can also tune the pipeline itself. GitLab notes that some jobs could safely run in an earlier stage without harming the project if they fail, and moving them can speed up CI pipelines.

Build once and mirror production
A common mistake is rebuilding the code for every stage. JetBrains warns that this introduces inconsistencies, and recommends that you build only once: promote the same build artifact through each stage of the pipeline and ultimately release it to live. It also suggests versioning artifacts and storing them in a central artifact repository such as Nexus rather than in source control (JetBrains TeamCity guide).
Gatling’s guide makes the same point in its own summary: build artifacts once, version infrastructure and configuration, and keep staging close to production (Gatling).
GitLab adds that when testing and production environments match, developers can rely on the results and deploy with confidence. It also describes the test pyramid, where unit tests catch most errors and end-to-end tests act mainly as a safeguard (GitLab).
Environments drift when they live too long. JetBrains says long-running pre-production environments can diverge from the original setup, and that refreshing test and staging environments between each pipeline run is worth investing in. Its suggestions are to host them in containers or virtual machines and to script creation and teardown as infrastructure as code.
Which mistakes quietly break CI?
Martin Fowler is quoted by Thoughtworks as saying that continuous integration doesn’t get rid of bugs, but does make them dramatically easier to find and remove. The same post lists five common mistakes that undermine this, including these (Thoughtworks, February 2022):
- Infrequent check-ins: code stays on laptops while others keep integrating, so merge conflicts pile up.
- Long-lived feature branches: Thoughtworks calls this closer to continuous isolation, or CI theatre.
- Broken builds left broken: a failing build is not the problem, but one that stays broken blocks other check-ins.
- Long build times: they work against the main reason for CI, which is faster feedback.
The remedies are concrete. Thoughtworks advises avoiding long-lived feature branches and keeping a single source-of-truth branch. Where pull requests need approval, it suggests short-lived branches for each task, which keeps reviews smaller.
For a broken build, be disciplined about fixing it as soon as possible. If the fix will take a lot of time, revert the commit so one person can investigate while everyone else is unblocked.
SPK and Associates’ December 2015 post lists approximately ten key principles, including that everyone commits to the baseline every day (SPK and Associates, 2015). Its advice on test scope is realistic: ideally all tests run with every build, but that is frequently not practical, so running the tests for the affected modules and then the full set on aggregated changes can make more sense.
Learn from failures and protect the pipeline
GitLab recommends a blameless response to failures: instead of asking who caused the failure, ask what caused it. If failed builds show a pattern, look at the underlying causes, such as non-code errors that fail builds unnecessarily, where an allow_failure parameter may help (GitLab).
GitLab also suggests referencing documentation in READMEs and building it into onboarding for new team members. That way the pipeline’s rules do not live only in a few heads.
Your pipeline holds access to your code and to the credentials that deploy to production, which JetBrains calls a prime target for attackers. Its checklist is short (JetBrains TeamCity guide):
- Secure access to version control repositories and require multi-factor authentication.
- Never store credentials in source code; use a dedicated secret store and keep them out of logs and build artifacts.
- Check third-party dependencies for known vulnerabilities as part of CI checks.
- Review changes from third parties before triggering a build.
Finally, adapt all of this to your team. AWS’s DevOps Guidance, published September 20, 2023, says there is no one-size-fits-all approach to adopting DevOps and that you should tailor its recommendations to your environment, quality and security needs (AWS).
How do you put these practices in order?
You do not need to adopt everything at once. A sensible sequence is:
- Put code, configuration and scripts in version control and make every commit trigger a build.
- Shorten commits and branches until the whole team integrates at least daily.
- Speed up the build and order tests so the quickest run first.
- Build the artifact once and promote it through production-like, regularly refreshed environments.
- Add blameless reviews of failures and the security checks above.
GitLab’s closing advice is that the best continuous integration system is the one you actually use. If you are still choosing a tool, the comparison of github actions vs jenkins can help you weigh the options. Once you have picked one, the github actions tutorial shows how to set up a first pipeline.
Frequently asked questions
What is the most important continuous integration best practice?
Show answer
GitLab’s guide says it is to commit early and commit often, because small problems are easier to fix than big ones and there is less code to sort through when something breaks (GitLab).
How fast should a CI build be?
Show answer
Ten minutes is the usual yardstick. Treat Martin Fowler’s ten-minute build as a target to work toward rather than a hard limit, because GitLab says most modern projects can meet it and every minute saved is repaid on each commit (GitLab).
Should every test run on every commit?
Show answer
Not necessarily. SPK and Associates’ 2015 post says running all tests with every build is the ideal but frequently not practical, and suggests running tests for affected modules first (SPK and Associates). JetBrains similarly advises balancing test coverage against performance.
What should you do when the build breaks?
Show answer
Fix it as soon as possible. Thoughtworks advises that if the fix will take a lot of time, you should revert the commit so one person can investigate while others stay unblocked (Thoughtworks).



