Bamboo is the continous integration service by Atlassian, the company owning the code management service Bitbucket (as well as the Jira issue tracker and Confluence wiki). Bamboo can run test suites and build any kind of artefact like generated documentation or installable packages. It integrates with Amazon Web Services, allowing to spin up EC2 instances as needed. So far, I mostly worked with travis-ci, because of open source projects I maintain on github.com. What Bamboo does really better than travis-ci – besides supporting other code repository SaaS than github.com – is the dynamic allocation of your own EC2 instances. Bamboo is just the manager, and can be configured to spin up EC2 instances when the number of tests to run increases. This keeps the costs at Amazon to a minimum while offering large capabilities to run tests when needed.

Besides licensing a Bamboo CI server to run yourself, you can also use it as a cloud service. I recently helped set up tests with this. Unfortunately, the documentation is really worse than expected, and the integration hampered by really silly mistakes that we had to dig up in discussion boards and on stackoverflow. This blog post contains a few notes if you want to do the same that hopefully will help others facing the same challenges. A word of caution: we did most of this in March and April 2016 – things might get fixed or change over time


Permissions for starting EC2 Instances

When setting up the Bamboo cloud service, you provide it your EC2 credentials. Bamboo will use them to create a bamboo user in AWS that it will use to start EC2 instances. Unfortunately, it does not give the user enough permissions to do so. After setting up Bamboo, log into AWS and find the bamboo user and give it enough permissions to spin up instances. Bamboo also won't tell you what is wrong, just saying that it failed to start a server.

Note that it takes a little moment until Bamboo spins up an instance, and while starting EC2 is quite fast, the time until the Bamboo Agent connects with the Bamboo server takes a couple of minutes. So don't worry if it takes a moment after set up.

Trigger Automatic builds

Once you connected Bamboo with Bitbucket, you create a project. You can specify that the build should be automatically started on every Bitbucket commit. So Bitbucket and Bamboo are both owned by Atlassian. Unfortunately, you need to manually specify the Bitbucket IPs in Bamboo as IPs that are allowed to trigger builds. That IP field only accepts except IPs, no ranges or wildcards. This page helpfully lists all the 50+ IPs Bitbucket might use.

Customizing the Test Runner

You can use any EC2 image, including custom images. Most of the time, there are much easier solutions and even the EC2 EBS mentioned in the documentation is overkill. There is a simple field in Bamboo to specify shell commands that are executed as root on instance startup. To find it, go to Bamboo Administration => Overview => Elastic Bamboo / Image configurations => {the image you want} – “Edit” => Instance startup script .

You can use the shared keys to ssh into an EC2 test runner and try out the commands you need. Just make sure you keep track of all of them for copying into the startup script. The runner could stop at any point, at which point changes made manually on the runner are lost. And you want new runners to be set up properly.

If you change something in the “Instance startup script”, you should stop all instances and let Bamboo start new ones to have the changes take effect. I recommend to do that even if you first did things manually to try out, and verify that the script was actually working correctly.

PHP on Bamboo

While the Amazon images list phpunit versions, they omit the PHP version itself. With good reason, its only the outdated and unmaintained 5.3 version. Unless you are into PHP archeology, you want to use a newer version. A good choice is the Ubuntu Stock Image, which has PHP 5.6. Simply disable all other images in the Elastic Bamboo / Image Configurations section. If you need more than the default PHP extensions, install them with the Instance startup script (see above). E.g. if you need curl, do apt-get install php5-curl.

If your project uses Composer (and it should!), best also add the composer installation to the Instance startup script.

Our project had a phpunit.xml.dist  file in the root folder. Normally Phpunit picks this .dist file if there is no phpunit.xml in the folder. But on Bamboo, tests failed with autoloading not working at all, until we realized that we need to specify the parameter -c phpunit.xml.dist  in the Phpunit task definition explicitly, otherwise Bamboo uses its own stock phpunit.xml file that makes no sense, instead of letting Phpunit pick the right file.