Coming from a development background, notably as a Java developer, the use of automated build tools has always been a top priority. People at Cloudaxis, myself included, have been using Jenkins for over ten years, all the way back to when it was known as ‘Hudson’.
So when AWS decided to integrate an automated build tool into its catalog, we felt we had to give it a try. Anyone who has worked extensively with Jenkins knows that it is a very open tools with literally hundreds of plug-ins that allow you do just about anything you would need. We did not expect CodeBuild to offer all the same possibilities, but wanted to know what it was capable of and in what context it should be used instead of Jenkins. Here is what we came up with:
CodeBuild allows you to retrieve your code from a limited number of sources, including
- GitHub Enterprise
- AWS CodeCommit
- AWS S3
From there you can choose your runtime from a fairly comprehensive list of stacks:
We made a Java build which runs on Maven, and allows you to enter you build commands. This gives you the ability to do pretty much anything you would do if you were running it locally. This however brings up a major shortcoming: as it has no local Maven repository as you would locally or on a dedicated Jenkins server, it has to download any and all artifacts it needs every time it builds. That means that a build that might take less than a minute on a dedicated server could take 4-5 minutes on CodeBuild.
Full CI/CD Pipeline
We created a full CI/CD pipeline using BitBucket, CodeBuild, Lambda, S3 and CodeDeploy:
The code was stored in BitBucket and retrieved by CodeBuild, and then built. The resulting artifact is then stored at a specified location in S3. The bucket containing the artifact has an event that is triggered from any PUT, POST or COPY on that bucket which triggers a Lambda function. The Lambda function tells CodeDeploy that a new build is available, at which point CodeDeploy retrieves it from the bucket and deploys it to the EC2 instances.
The price per build depends on many factors, including the memory you allocate to the build and whether you are running it on Linux or Windows. Full pricing information an be found here from the AWS website. In using the build.general1.medium instance type running on Linux, which gives 7GB of memory and 4 vCPUs, our build took about 4.5 minutes, and was billed at a rate of $0.01/minute. So each build would cost about 5 cents USD.
While that may seem cheap, if you have a development team pushing builds through a CI/CD pipeline with unit tests on multiple environments, you are going to be looking at multiple dollars per day. Again, that might not sound like much, but for that price you can easily setup a Jenkins server on an on-demand EC2 instance and run hundreds of jobs each day while enjoying the flexibility of Jenkins plugins.
- Quick: If you are building a small project and don’t need a dedicated Jenkins instance, CodeBuild is a great solution. We found it relatively easy to get setup and get going. If you just have one project to build, it is faster than setting up a new Jenkins instance
- Jobs as code: the jobs you create can be saved as code, which is useful, especially if you want to create similar or duplicate jobs
- AWS Integration: running your builds directly on AWS gives you the ability to use any of the other services, should you need them
- History: your build history is saved, along with the artifacts that build produced.
- Logging: the logs are sent to Cloudwatch logs and can of course be retrieved at a later date. The console gets updated on the webpage as the build executes, so you can see what is going on in real time.
- Maven: when using Maven, it has to download all necessary artifacts every time. That makes for slow builds.
- SCM Polling: one of the features we regretted the most was its inability to poll the SCM for changes. That means you either have to create a script yourself, or launch your builds manually.
- Pricing: would rapidly become more expensive than using a dedicated instance for Jenkins if you have a large team of developers needing numerous builds throughout the day.
- Plug-ins: does not offer the plethora of plugins that are available for Jenkins.
CodeBuild is a great tool for simple projects or small teams that want to build a CI/CD pipeline without the need for a full blown Jenkins instance. If you can live without the bells & whistles that Jenkins provides, CodeBuild is a cost-efficient way to create a pipeline.