# CodeBuild - A fully managed build service in the cloud. - Compiles your code, runs unit tests, and produces artifacts that are ready to deploy. - Eliminates the need to provision, manage, and scale your own build server - Provides prepackaged build environments for popular programming languages and build tools such as Apache, Maven, Gradle, and more. - You can also customise environments to use your own build tools - Scaled automatically to meet peak build requests. ## Workflow 1. Trigger a build * You can trigger a build with AWS Console, CLI, SDK or [[_CodePipeline|CodePipeline]] trigger (like pushing to `main`). 2. Passes the code onto CodeBuild 3. You give it a `buildspec.yaml` file, which is generally part of your code base. * You can override it with other build commands. 4. Push into a bucket, or any other AWS SDK action (I think?) ## Build Environments The Docker images that run the CodeBuild, can be managed by AWS or you. If you need specific software, you need to make an image and upload it to ECR and reference it in the pipeline. ## `buildspec.yaml` - Provides the build instructions. - Needs to be in the root of your project folder (`/buildspec.yaml`) (by default). ### Phases 1. `install`: only for installing packages in the build environment. (Code gets pulled before this step.) 2. `pre_build`: commands that run before building. 3. `build`: commands that you run during the build. 4. `post_build`: commands you run after the build. ### Artifacts Where we can find the build output How it prepares it for uploading to S3 output bucket. Basically Zips that go to S3, or ECR images, anything else that SDK can touch. ## Use Cases - Generating static pages to host on S3. - Run test code & report test coverage. For example, a developer needs to ensure their code passes all tests before being allowed to make/merge a PR.