This is the second, and final part, about configuring Bamboo EC2 Windows images. In the first part, we showed you how to set up your Windows elastic instance with EC2 on Bamboo. In this post we will focus on basic image customisation methods. If you want in-depth information on configuring Bamboo with EC2 or simply want to understand how a Windows EC2 image is set up, this blog is meant for you.

Using your existing EC2 images with Bamboo

In some cases, instead of using a stock Bamboo image as a starting point for your customisation, you may want to start with a non-Bamboo image (for example, one containing a different Windows version or possibly, additional software from a third party vendor). The process of creating Windows images and keeping them up to date used to be very complicated, but Bamboo 3.4 makes it as simple as possible. The procedure outlined below consists of two phases: in the first phase, install all necessary software on your instance, just like during a regular customisation. In the second phase, download Bamboo agent data on the image. Keep in mind that the procedure outlined below is meant for advanced (or patient!) users of EC2/Windows.

Phase 1: Start your image

Start your image using your tool of choice, e.g. the AWS Management Console. Log in to that instance with an Administrator account.

  1. Create the user account that will be used by the Bamboo agent. The account name is up to you, I will use Bamboo in the examples below. All builds running on your machine will use this account. It can be a regular user (i.e. it does not need to be a Power User or Administrator, unless your builds require it). Set up a password for that user. The default user on a Windows image has a user name of Bamboo with a password of Atlassian1.
  2. Important: by default, a newly created user should be denied remote login rights (which is supposed to happen). Please make sure that you cannot log in using that users credentials (unless you change them to non-default ones).
  3. If your builds are not headless (i.e. they show/manipulate windows, like Selenium does), you need to set up autologin for your Bamboo account (don’t worry, this will not let remote users in). To do this, run control userpasswords2 and uncheck “User must enter a user name and password to enter this computer”:
  4. Reconfigure the Windows firewall to accept TCP connections on port 26224. No other inbound connections are necessary for Bamboo. Don’t worry about changing the EC2 security group setting for this port, Bamboo will set it up automatically:
  5. Install a supported Oracle Java version (6 or 7).
  6. Grab atlassian-bamboo-agent-elastic-installer.jar from Maven. Store it in the %USERPROFILE% directory of the Bamboo user you’ve created.
  7. A batch file should launch with your Windows instance startup. In order to do this, use the Windows Task Manager (Start->Administrative Tools->Task Scheduler), and set up a new task with Trigger “At system startup” and Actions “Start a program->PATH TO YOUR BATCH FILE”. Remember to select “Run whether user is logged on or not” in the “General” tab.
    @echo off
    set OLD_PWD=%CD%
    for %%I in (%USERPROFILE%) do set HOME=%%~pnxI
    echo JAVA_HOME: %JAVA_HOME% >bamboo-elastic-agent.out
    echo PATH: %PATH% >>bamboo-elastic-agent.out
    echo HOME: %HOME% >>bamboo-elastic-agent.out
    "%JAVA_HOME%/bin/java" -version 2>>bamboo-elastic-agent.out
    "%JAVA_HOME%/bin/java" -jar atlassian-bamboo-agent-elastic-installer*.jar >>bamboo-elastic-agent.out 2>&1
    cd %OLD_PWD%
    set OLD_PWD=

    The task manager will warn you that the account needs to be able to log in as a batch job. Make sure the “Log on as batch job” policy is set for the user. This policy is accessible by opening the Control Panel -> Administrative Tools -> Local Security Policy. In the Local Security Policy window, click Local Policies -> User Rights Assignment -> Log on as batch job:

  8. Make sure that your Bamboo user is allowed to read both the batch file and the installer jar.
  9. Run the batch file from the command line as your Bamboo user, e.g. runas /user:Bamboo syncAndRunBamboo.bat
  10. Look for the %USERPROFILE%/bamboo-elastic-agent.out file. If it exists and contains an error message stating that agent was not run within an EC2 instance started by Bamboo Server, you’ve successfully completed the first phase.
  11. Bundle your instance. Make note of the AMI id of the new image.

Phase 2: Start your image from Bamboo

Note: if you fail to complete the following steps within ~40 minutes, Bamboo will shut down your instance, so remember to save your work if you’re running out of time (i.e. create an interim image).

  1. Start the image you want to customise from Bamboo by defining an image configuration for it (use the AMI id from the last step of phase 1).
  2. Just like in phase 1, run the batch file from command line as your Bamboo user, e.g. runas /user:Bamboo syncAndRunBamboo.bat
  3. If everything went well, the installer will perform two steps:
    1. Create a /opt/bamboo-elastic-agent directory structure . If it appears, Java is working correctly on that machine and the connection to S3 is working.
    2. Start the agent and create a Bamboo Agent Home which will create the directory and populate it with data pulled from Bamboo server.
  4. If everything went well, you should see the agent appear in the Bamboo instance list. That’s it, save the image, define a new image confguration, kill the instance, and try running it from Bamboo.

Customize your EC2 Image

Now you are armed with the ability to perform any customization task needed to run Bamboo with Ec2 Windows.

Got questions? If you require any further assistance, feel free to ask a question at our community support site. Chances are, your problem has already been solved by someone, and if not we will do our best to get you going.

Fresh ideas, announcements, and inspiration for your team, delivered weekly.

Subscribe now

Fresh ideas, announcements, and inspiration for your team, delivered weekly.

Subscribe now