Course contentsShow
← Cloud and Infrastructure
Lesson 1825 of 2,98938. AWS Native CI/CDFree lesson

Build Phases: Install, Pre-build, Build, Post-build

Understand each build phase's purpose and when to execute commands like dependency installation and testing.

Build Phases: Install, Pre-build, Build, Post-build

What You'll Learn

You'll understand the four distinct build phases in AWS CodeBuild and when to execute specific commands in each phase for optimal pipeline organization.

Understanding Build Phases

Think of a CodeBuild execution like preparing a meal: you gather ingredients (install), prep them (pre-build), cook (build), and plate the dish (post-build). Each phase serves a specific purpose and runs sequentially.

The Four Build Phases

Install Phase This is where you install runtime versions and essential tools needed for your build. Commands here might include installing specific versions of Node.js, Python, or build tools. This phase runs before anything else and sets up your build environment's foundation.

Pre-build Phase Use this phase for setup tasks that must happen before compilation or building. Common activities include logging into Docker registries, installing project dependencies (like npm install or pip install), or running security scans. Think of it as your "preparation zone."

Build Phase This is the main event—where actual compilation, testing, and artifact creation happen. Execute your build commands, run unit tests, compile code, or create Docker images here. This phase does the heavy lifting of transforming source code into deployable artifacts.

Post-build Phase The cleanup and finalization phase. Push Docker images to registries, package artifacts, run post-build tests, send notifications, or generate reports. Commands here run regardless of whether the build phase succeeded (unless you specify otherwise in your buildspec).

Execution Order Matters

Each phase runs in sequence. If a command fails in any phase, CodeBuild stops (unless configured otherwise), and subsequent phases won't execute. This structure helps you debug issues quickly—a failure in pre-build tells you it's a dependency problem, not a compilation issue.

Key Takeaway: CodeBuild's four phases organize your pipeline logically—install tools, prepare dependencies, execute builds, and finalize outputs—making pipelines predictable, maintainable, and easier to troubleshoot.