Course contentsShow
← Software Engineering
Lesson 654 of 1,93320. Continuous IntegrationFree lesson

Preventing Build Breakage

Running tests locally before pushing, using pre-commit hooks, and validating changes comprehensively.

Preventing Build Breakage

What you'll learn: How to stop broken code from reaching your CI pipeline through local validation and automated checks.

The best way to fix broken builds is to prevent them from happening in the first place. While committing frequently to mainline is critical for CI, you must ensure each commit is actually integration-ready. Think of it like proofreading an email before hitting send—catching mistakes early saves everyone time and embarrassment.

Running Tests Locally Before Pushing

Before pushing code, run the full test suite on your machine. This catches failures in your own environment before they break the shared build. It takes a few extra minutes, but prevents the entire team from grinding to a halt.

# Run all tests before pushing
npm test
# or
./gradlew test

If your test suite is large, at minimum run tests affected by your changes. Never skip this step to "save time."

Using Pre-Commit Hooks

Pre-commit hooks are automated checks that run locally before code is committed. They act as a safety net, preventing obviously broken code from even entering version control.

# Example pre-commit hook checking linting
#!/bin/sh
npm run lint
if [ $? -ne 0 ]; then
  echo "Linting failed. Fix errors before committing."
  exit 1
fi

These hooks enforce standards like code formatting, running quick smoke tests, or checking for obvious errors.

Validating Changes Comprehensively

Beyond tests, validate that your change actually works end-to-end. Did you update dependencies? Build from scratch. Modified configuration? Test with that configuration locally. Integration-ready means truly ready—not "probably works."

This comprehensive local verification catches issues that tests alone might miss.

Key Takeaway: Prevent build breakage by running tests locally, using pre-commit hooks for automated validation, and thoroughly checking your changes before pushing—treating integration as a privilege earned through diligence.