<![CDATA[

CodeBuild is Amazon’s continuous integration, CI, tool to provide you, the developer, a means of building and testing their code in the cloud throughout the development life cycle.

Continuous integration lets you catch defects and environmental issues earlier in the development process when it is cheaper to correct them both in time and cost. Continuous integration with CodeBuild helps you insure quality of your systems from the very beginning of the development life cycle.

This post will give you an introduction to AWS CodeBuild by explaining its benefits and walking you through setting it up for your own development project.  This post builds on the exercises presented in the post AWS DevOps Basics – Intro to CodeCommit so if you haven’t read that post yet go back to it first then you will be ready to continue here.

All set?  Great!  Let’s get started.

CodeBuild Benefits

Benefit #1: Less Costly Intervention Due to Code Defects

When you are continuously building the code you write and unit testing it, you will catch defects very early in the development life cycle.  Defects caught early on are far less costly to address than defects found near to or following deployment.

CodeBuild allows you to setup scheduled builds that point to your source control management system to build new versions of your code at regular intervals.  With integrated unit testing in CodeBuild you can also exercise your code to make sure no regression errors have been introduced since the last successful build.

Any build failures are immediately raised to your notification system of choice so you can quickly intervene and address new issues.

Benefit #2: Easy Integration with Multiple DevOps Tools

Although AWS offers a full range of DevOps tools in their suite, they do not require that you use all of them.

CodeBuild integrates with GitHub just as easily as it integrates with CodeCommit.  If you are a fan of Jenkins you can use it via the AWS CodeBuild Plugin for Jenkins to send Jenkins build jobs to CodeBuild.

This means you can keep all of the build workflows you’ve established with Jenkins but do away with the need to build and maintain your own Jenkins build farms.  When you transmit your build jobs to CodeBuild all of the environments you need are automatically apportioned to your builds.

You are only charged for the number of minutes it takes to complete your build.  No more excess infrastructure required.

Getting Started with CodeBuild

Now that you’re familiar with the benefits of CodeBuild it’s time to roll up your sleeves and get elbow deep in using it.

Step #1: Access the CodeBuild Console

Getting into the CodeBuild console is as easy as opening the AWS console, typing “CodeBuild” in the services search box and selecting the CodeBuild link from the search results.

This image has an empty alt attribute; its file name is CodeBuild-001.png

Step #2: Create a CodeBuild Project

Click the “Create build project” button to bring up the new project screen in CodeBuild.

Step #2.1: Name and Describe your CodeBuild Project

Enter a name for your project and a description of what your project is for.  As an added bonus you can check the “Enable build badge” checkbox to provide a visual indicator of your build’s status that can be accessed via the web.  This is an easy way for people to keep up with whether or not the build is currently working properly.

This image has an empty alt attribute; its file name is CodeBuild-002.png

Step #2.2: Select the Source Location for Your Build

Every good build requires source code to make the magic happen.  You need to specify where your source code lives so your build can extract it and work with it.  

This image has an empty alt attribute; its file name is CodeBuild-003.png

In the source provider select the provider you use from the drop down list.  You will see CodeBuild offers several options to choose from.

This image has an empty alt attribute; its file name is CodeBuild-003.1.png

If you are continuing the example I started in my post, AWS DevOps Basics: Intro to CodeCommit, choose the default, “AWS CodeCommit”.

From the “Repository” drop down, choose the repository that houses your code.

Step #2.3: Choose the Server Image to Use

Now you are ready to specify the server image that you want to use to host your build jobs.  You have several options on this screen.

This image has an empty alt attribute; its file name is CodeBuild-004.png

First you can choose either a “Managed Image”, one updated and maintained by CodeBuild.  Or, you can select a “Custom Image” from Docker.

For this exercise, choose the “Managed Image” option.

Next, select the operating system for the server.  You can choose between Ubuntu Linux and Windows.

In order for your build to run successfully it will need a to run within a service role.  If you are familiar with AWS and IAM security and you already have a role that you would like to use, you can select that role here.

If not, leave the “New service role” radio button selected and enter a role name.  This will create the role with the appropriate privileges assigned.

Step #2.4: Set Build Commands

CodeBuild uses YAML syntax to issue build commands during the build process.  You have two choices on how to include it in your CodeBuild project.

  1. You can create a buildspec.yml file and include it in your source code.
  2. You can insert build commands directly into your CodeBuild project.

The first option gives you the flexibility to change build commands while you are editing your code with no need to edit your CodeBuild project.

This image has an empty alt attribute; its file name is CodeBuild-005.png

Step #2.5: Set Output Artifacts

This final step of the CodeBuild project setup allows you to specify where your build results end up.  Both your compiled code as well as test results find their way here.

This image has an empty alt attribute; its file name is CodeBuild-006.png

Your options include: No Artifacts (if you are just doing a test), or AWS S3.

When you select S3.  You will be presented with a list of options to specify.

This image has an empty alt attribute; its file name is CodeBuild-007.png

First, select the bucket that you want your artifacts to land in and then provide a name for your artifacts package.  This is for organization and ease of reference later on.

You also have the option to enable semantic versioning.  This lets you specify your naming convention in your buildspec file so that each version conforms to a standard versioning pattern.

Specify the path of your output artifact and choose whether or not to include the build id in the artifact output path via the Namespace type option.

Next, decide whether on not you want your artifacts packaged as a zip file or not and select the appropriate radio button.

Finally, if your artifacts are meant to be shared with others, you will want to select the “Remove artifact encryption” check box.  Click the “Create build project” button and your project will be set up.

Step #3: Run the CodeBuild Project

Now for the moment of truth!

It’s time to execute your CodeBuild project and see what all the excitement is about.

Return to your list of project by selecting the “Build projects” link in the left navigation menu of the CodeBuild console.

Select the radio button for your new CodeBuild project and click the “Start Build” button.

You will be presented with some options to including environment variables that you can set for this instance of your build run.  Make any selections or changes you would like and click the “Start Build” button.

And you’re off!

This image has an empty alt attribute; its file name is off-to-races.png

Finishing Up

Once your build completes you will be able to examine the artifacts and see the results of your (hopefully) successful build.

From here you will be able to integrate this build with your CodeCommit repository via CodePipeline to trigger automatic builds whenever you commit changes to your repository.  I will be covering that setup in a future post.

If you would like to receive these posts directly in your email inbox please add your name and email below.  You will be subscribed to the mailing list and whenever I publish a post it will be on its way to your digital doorstep.

Thanks!

— Nat

]]>

Leave a Reply

Close Menu
×
×

Cart

%d bloggers like this: