Building Plugins for Bamboo

June 24, 2014

I want to make a change to the way the Tomcat deployment plugin works for Bamboo, so that I can deploy with a wildcard in the WAR file name. This will let me use Tomcat 7 features to deploy multiple copies of the same WAR file and have users automatically pick up the latest one.

I'm using Ubuntu Linux for this development.

Install the SDK

Atlassian provide an SDK that lets you run up local copies of their tools for testing. To install this SDK, we can add another apt repository. Instructions for installing the SDK are at https://developer.atlassian.com/display/DOCS/Install+the+Atlassian+SDK+on+a+Linux+or+Mac+System

# sudo sh -c 'echo "deb https://sdkrepo.atlassian.com/debian/ stable contrib" >>/etc/apt/sources.list'
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys B07804338C015B73
# sudo apt-get install apt-transport-https
# sudo apt-get update
# sudo apt-get install atlassian-plugin-sdk

Get a copy of the existing tomcat plugin

I want to modify an existing plugin, so the first thing to do is get the source for that:

$ hg clone https://bitbucket.org/atlassian/bamboo-tomcat-plugin bamboo-tomcat-plugin
requesting all changes
adding changesets
adding manifests
adding file changes
added 94 changesets with 216 changes to 39 files
updating to branch default
31 files updated, 0 files merged, 0 files removed, 0 files unresolved

Create New Bamboo Plugin

We need to use the atlas command to create a new bamboo plugin:

$ tjs@host:~/atlas/drumcoder-bamboo$ atlas-create-bamboo-plugin

We'll use the following values when prompted:

groupId: com.drumcoder.bamboo
artifactId: drumcoder
version: 1.0
package: com.drumcoder.bamboo.plugin

and then we'll have to confirm these with a Y.

To set this up to work in Eclipse, we need to run another command:

$ cd drumcoder
$ atlas-mvn eclipse:eclipse

this will download lots of stuff, and take a while. It should end with:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11:15 min
[INFO] Finished at: 2014-07-02T12:46:22+00:00
[INFO] Final Memory: 33M/484M
[INFO] ------------------------------------------------------------------------

You should now be able to use File/Import/Existing Projects into Workspace in Eclipse to get the project in.

Add Task Code

I copied in the existing tasks from the source downloaded earlier. I then made the changes I need to support deploying with a wildcard in the WAR file name.

I added the task in atlassian-plugin.xml so I ended up with:

<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
    <plugin-info>
        <description>${project.description}</description>
        <version>${project.version}</version>
        <vendor name="${project.organization.name}" url="${project.organization.url}" />
        <param name="plugin-icon">images/pluginIcon.png</param>
        <param name="plugin-logo">images/pluginLogo.png</param>
    </plugin-info>

    <!-- add our i18n resource -->
    <resource type="i18n" name="com.drumcoder.bamboo.plugin.tomcat.i18n" location="com.drumcoder.bamboo.plugin.tomcat.i18n"/>

  <taskType key="myDeployAppTask" name="Deploy to Tomcat" class="com.drumcoder.bamboo.plugin.tomcat.tasks.DeployAppTask">
    <description>Deploy WAR to Tomcat server, with wildcard WAR file name</description>
    <category name="deployment"/>
    <configuration class="com.drumcoder.bamboo.plugin.tomcat.configuration.DeployAppConfigurator"/>
    <resource type="freemarker" name="edit" location="com/drumcoder/bamboo/plugin/tomcat/editDeployApp.ftl"/>
    <resource type="freemarker" name="view" location="com/drumcoder/bamboo/plugin/tomcat/viewDeployApp.ftl"/>
    <resource type="download" name="icon" location="com/drumcoder/bamboo/plugin/tomcat/pancredit.png"/>
    <help key="tomcat.task.help" />
  </taskType>
</atlassian-plugin>

Testing

You can test the plugin in a local temporary Bamboo by running

$ atlas-run

from within the plugin source directory (same directory as pom.xml)

You can then visit http://localhost:6990/bamboo/ and run a full Bamboo instance with your plugin installed. Note that the output for the atlas-run command might look like it has hung - if this happens, try the URL it has probably worked!

Releasing

To release the plugin for use, run:

$ atlas-package

This will product a jar file for your plugin in the target directory.

To deploy this into your Bamboo, copy the .jar file to your $BAMBOO_HOME/plugin directory and restart bamboo.

References