Short feedback cycles should be a major goal for every development team. Ideally this feedback cycle is not only limited to automated tests, but to real life user feedback. At Atlassian we are pushing hard to continuously deploy our products internally which enables us to gather and react to feedback early in the development cycle of new features. But this also means that deploying new versions of the applications has to be easy and automated.

Bamboo Tomcat Plugin

The Bamboo Tomcat Plugin makes it easy to get started deploying and managing your app through Bamboo without having to edit a single Ant build.xml or a Maven pom.xml.

Just like Atlassian, many of our customers use Apache Tomcat to deploy their Java web applications. While it is possible to deploy webapps using Ant or Maven many developers find that the configuration is hard to maintain. Also, the tools are not so easy to understand for those not in the know and it can mean you end up hard coding a bunch of environment specific configuration in your build scripts.

Installing the Plugin

You will need to follow the steps below before beginning:

Setting up Tomcat

1. Download the Tomcat 7 distribution and unzip it on your file system
2. Add a new user for Bamboo to use the Tomcat Manager application by adding the following line in “conf/tomcat-users.xml” between the tags > <user username=”bamboo” password=”bamboo” roles=”manager-script,manager-gui”/>

3. Then start tomcat by running the “bin/” on Linux or Mac or “bin/startup.bat” on Windows
4. Test your changes by browsing to http://localhost:8080/manager and using the username and password we put in the tomcat-users.xml. If you have followed the instructions correctly you should see a page titled “Tomcat Web Application Manager” and a list of the running applications on your instance.

Deploying the Test Application

To make this a little easier to follow I’ve created a sample project which makes use of a Grails project hosted on BitBucket.

Creating the Build Plan

1. Click “Create New Plan” and Fill out the Plan Details (you can set these to whatever you want)
2. Under “Source Repository” choose the Source Control option “Mercurial” and provide in the “Repository URL” field
3. Then click the “Configure Tasks” button at the bottom of the page.

Once you have completed the previous steps you should be presented with a screen that looks like the one below. Click “Add Task”.

Configuring the Tasks

We are now going to add the Grails task that will produce our war file. Type in the search box “grails” and click the “Grails” task.

Add a single line, “war”, to the default text in the Grails Commands text area and click “Save”.

Add a another Task by clicking the “Add Task” button and add the “Deploy Tomcat Application” Task

Now its time to configure our Tomcat webapp deployment. Fillout the username and password fields using the details we put in tomcat-users.xml (These should be both “bamboo” for the username and password if you followed this guide to the letter).
The “Application Context” field specifies where the application should sit on the Tomcat Server once we have deployed it. For this example we will use the value “/myapp” and it will have a final url of “http://localhost:8080/myapp”.

In the “WAR File” field use the value “target/tomcat-test-0.1.war” as this is where Grails will create the war file. Click “Save” when your ready.

Lets run our new deployment plan by checking the “Enable this plan” checkbox and clicking “Create”

Checkout your newly deployed webapp!

Now lets check if your deployment has run successfully. First navigate to the logs of your Job and you should see towards the very end of the log something like:

> Deploying application with war file ‘target/tomcat-test-0.1.war’ to context ‘/myapp’ to server [http://localhost:8080/manager/](http://localhost:8080/manager/)

> Application was successfully deployed.
Great! The deployment ran successfully as far as Bamboo is concerned. Browse over to your new webapp at [http://localhost:8080/myapp](http://localhost:8080/myapp) and check it out – you should see a page like the following:

If you see that page then your application is running happily in Tomcat – all deployed from Bamboo!

How it works

The Tomcat plugin uses the HTTP based scripting interface to the Tomcat Manager application that ships by default with Tomcat. Through this interface Tomcat allows you to start, stop, reload, deploy and undeploy applications running in the Tomcat instance. Bamboo exposes these interfaces via the new Bamboo 3.1 Task system by providing a Task for each of these operations.

Things to try at home

* Forking the test project on Bitbucket and changing the “grails-app/views/index.gsp” file and watch as the example app updates within Tomcat
* Try the tutorial with your own webapp project in place of our example application
* Create a new plan that starts, stops, reloads and undeploys the test application. There are Bamboo Tasks in the plugin for each of these operations.

If you had any troubles with the tutorial please let me know in the comments and Ill try my best to help you out. You can also catch me talking about development tools over on my Twitter account. Don’t forget that the [Tomcat Plugin is open source] and we would love to work with the community on improving it.

Continuous Deployment with Bamboo and Tomcat...