Archive for the ‘development process’ Category.

Testing Atlassian Rest Plugins

With the latest versions of the Atlassian products, you can now add your own rest component plugins.

This is really cool, however, while testing rest plugins is actually pretty easy, figuring out exactly how to do it can drive a person crazy. And so I thought I’d write this post in hopes of saving others hours of research time.

The Project

For this example we’re just going to create a really simple rest resource that returns a list of the projects in JIRA.
I’m not going to walk through plugin development step-by-step but I’ll get us started…

Create a project

Let’s create our project using the Atlassian Plugin SDK.
Just open a terminal and navigate to your base workspace folder. Then run:

atlas-create-jira-plugin

When asked for the plugin name, call it jira-projects-rest

Add some Maven Dependencies

We’ll need a few libraries to help us test, just add the following to the pom dependency list

        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
            <version>1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins.rest</groupId>
            <artifactId>atlassian-rest-common</artifactId>
            <version>1.0.2</version>
            <scope>provided</scope>
        </dependency>
 
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.3</version>
            <scope>provided</scope>
        </dependency>
 
        <dependency>
	    <groupId>com.sun.jersey</groupId>
	    <artifactId>jersey-test-framework</artifactId>
	    <version>1.1.2-ea</version>
	    <scope>test</scope>
	</dependency>

Add the rest descriptor

Once the project is created, edit the atlassian-plugin.xml and add our rest component:

<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.artifactId}" plugins-version="2">
    <plugin-info>
        <description>${project.description}</description>
        <version>${project.version}</version>
        <vendor name="${project.organization.name}" url="${project.organization.url}" />
        <application-version min="4.0"/>
        <bundle-instructions>
            <Import-Package>org.apache.commons.collections,*;resolution:=optional</Import-Package>
        </bundle-instructions>
    </plugin-info>
 
    <rest key="projectsService" path="/projectfinder" version="1.0">
        <description>Provides a service that lists JIRA projects</description>
    </rest>
 
    <component key="projectFinder"
        name="Project Finder"
        class="com.sysbliss.jira.plugins.util.ProjectFinder"/>
 
</atlassian-plugin>

The guts

So in the plugin descriptor you’ll notice we have a component named “projectFinder”.
This is a simple helper class that’s not really required, but it helps to decouple our service wrapper and would make sense in a more complex plugin.

The ProjectFinder is responsible for looking up and returning our project list:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.sysbliss.jira.plugins.util;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
 
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager;
 
public class ProjectFinder {
 
    private final ProjectManager projectManager;
 
    public ProjectFinder(final ProjectManager projectManager) {
	this.projectManager = projectManager;
    }
 
    public List<Project> getProjects() {
	List<Project> projects = projectManager.getProjectObjects();
	if (projects == null) {
	    projects = Collections.<Project> emptyList();
	}
 
	return projects;
 
    }
}

The service wrapper

So now we need a service wrapper. This basically contains 2 classes:

  • ProjectsResource – The class that will be our jersey Resource
  • RestProject – a JAXB class that represents a single project

ProjectsResource.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 
package com.sysbliss.jira.plugins.rest;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
 
import com.atlassian.jira.project.Project;
import com.atlassian.plugins.rest.common.security.AnonymousAllowed;
import com.sysbliss.jira.plugins.util.ProjectFinder;
 
@Path("")
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public class ProjectsResource {
 
    private final ProjectFinder projectFinder;
 
    public ProjectsResource(final ProjectFinder projectFinder) {
	this.projectFinder = projectFinder;
    }
 
    @GET
    @Path("projects")
    @AnonymousAllowed
    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    public Response getProjects() {
 
	final List<Project> projectList = projectFinder.getProjects();
	final List<RestProject> restProjectList = new ArrayList<RestProject>();
	for (final Project project : projectList) {
	    restProjectList.add(new RestProject(project.getName()));
	}
 
	final GenericEntity<List<RestProject>> entities = new GenericEntity<List<RestProject>>(restProjectList) {};
 
	return Response.ok(entities).build();
    }
}

Let’s move on to the RestProject that represents a JIRA project.
For this example, I’m just going to include the name field, but you could add all the other stuff if needed.

RestProject.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
package com.sysbliss.jira.plugins.rest;
 
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
 
import net.jcip.annotations.Immutable;
 
@Immutable
@XmlRootElement
public class RestProject {
 
    @XmlElement
    public final String name;
 
    public RestProject() {
	this.name = "";
    }
 
    public RestProject(final String name) {
	this.name = name;
    }
}

Unit Testing

Although I gave you the implementation code first, this was actually written test-first and I highly advise all others to do the same

At this point if all is well, we have a simple rest service in JIRA that returns a list containing RestProject objects.
The first thing we want to test is our ProjectFinder class. These will be unit tests.

Since we will need to mock out JIRA Project objects, it’s handy to write a little test utility for that.
Note: All the test classes use the Mockito framework for making mocks.

ProjectMockUtils.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
package com.sysbliss.jira.plugins.test.util;
 
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
 
import java.util.Collection;
 
import com.atlassian.jira.project.Project;
 
 
public class ProjectMockUtils {
 
    public static Project createMockProject(final Long id, final String name, final String key) {
	final Project project = mock(Project.class);
 
	when(project.getId()).thenReturn(id);
	when(project.getName()).thenReturn(name);
	when(project.getKey()).thenReturn(key);
 
	return project;
    }
}

And now on to the unit tests. These are pretty simple and shouldn’t require too much explanation…
Note: The unit tests are using the TestNG framework.

ProjectFinderTest.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
package com.sysbliss.jira.plugins;
 
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
 
import java.util.ArrayList;
import java.util.List;
 
import org.testng.annotations.Test;
 
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager;
import com.sysbliss.jira.plugins.test.util.ProjectMockUtils;
import com.sysbliss.jira.plugins.util.ProjectFinder;
 
public class ProjectFinderTest {
 
    @Test
    public void projectsAreFound() {
	final List<Project> projects = new ArrayList<Project>();
	projects.add(ProjectMockUtils.createMockProject(1L, "Project 1", "PRJ1"));
	projects.add(ProjectMockUtils.createMockProject(2L, "Project 2", "PRJ2"));
 
	final ProjectManager projectManager = mock(ProjectManager.class);
	when(projectManager.getProjectObjects()).thenReturn(projects);
 
	final ProjectFinder finder = new ProjectFinder(projectManager);
 
	final List<Project> found = finder.getProjects();
 
	assert found.size() == 2 : "Expected 2 projects but got " + found.size();
    }
 
}

So that’s that. I’m keeping it to that one method for this example. In real life, you’d have a bunch of boundry tests, etc, etc.

Next, and equally as exciting, almost the same exact test for the resource wrapper.

ProjectsResourceTest.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
package com.sysbliss.jira.plugins;
 
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.ws.rs.core.Response;
 
import org.testng.annotations.Test;
 
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager;
import com.sysbliss.jira.plugins.rest.RestProject;
import com.sysbliss.jira.plugins.rest.ProjectsResource;
import com.sysbliss.jira.plugins.test.util.ProjectMockUtils;
import com.sysbliss.jira.plugins.util.ProjectFinder;
 
public class ProjectsResourceTest {
 
    @Test
    public void resourceProjectsAreFound() {
 
	final List<Project> projects = new ArrayList<Project>();
	projects.add(ProjectMockUtils.createMockProject(1L, "Project 1", "PRJ1"));
	projects.add(ProjectMockUtils.createMockProject(2L, "Project 2", "PRJ2"));
 
	final ProjectManager projectManager = mock(ProjectManager.class);
	when(projectManager.getProjectObjects()).thenReturn(projects);
 
	final ProjectFinder finder = new ProjectFinder(projectManager);
 
	final ProjectsResource resource = new ProjectsResource(finder);
 
	final Response response = resource.getProjects();
 
	final GenericEntity<List<RestProject>> entities = (GenericEntity<List<RestProject>>) response.getEntity();
 
	final List<RestProject> restProjects = entities.getEntity();
 
	assert (restProjects.size() == 2) : "Expected 2 projects but got " + restProjects.size();
    }
 
}

The above test is a little more interesting in the fact that it’s using our jersey resource to test that our resource classes are working properly and that we are getting the correct model objects from the Response class.

So that’s it for the unit tests. Pretty simple and doesn’t require any external connections to anything.
On to the interesting parts….

Integration Testing

The new Atlassian Plugins SDK provides some really cool stuff to help with integration testing and coupled with a few little “tricks” it’s pretty painless.

The Goal

The goal of our integration test harness is to deploy our plugin into a running JIRA instance, provide a known set of data, and actually make http requests to our new resource to verify that everything is working properly.

Before we can get started writing our test, we need to do a little setup.

Creating a dataset

We’re going to need a known set of data in our JIRA instance; namely, 2 empty projects.
The first step in creating the data is to boot up JIRA. Once again, the plugins SDK makes this easy….

Running JIRA

In a terminal, navigate to the project root and run:

atlas-run

If you’ve never run this previously, get some coffee…. maven’s going to do some web surfing for a while.
Once maven has completed, the SDK will boot up JIRA and deploy our plugin. At this point, we don’t really care about our rest resource…. we’re just going to make use of JIRA.

So now just open a browser and point it at: http://localhost:2990/jira

This will bring up JIRA and put you at the dashboard. Login using admin/admin as user/pass.

Create Projects

Finally, go to the JIRA administration section and create 2 projects. It doesn’t matter what they’re called, and they don’t need to have any issues or anything, just be sure there are 2 and only 2 projects created.

After the projects are created, use the backup to xml tool to export the data to an xml file.
The file should be saved as: [project-root]/src/test/xml/it-data.xml

That’s it. Now just CTRL-C in the terminal to shutdown JIRA.

Test Properties

We’re going to be making use of the JiraWebTest class (more on that in a bit) which requires us to make a properties file for integration testing.

Create a file: [project-root]/src/test/resources/localtest.properties
The contents of the file should be:

jira.protocol = http
jira.host = localhost
jira.port = 2990
jira.context = /jira
jira.edition = all
# Please note jira.xml.data.location needs to be the full path
jira.xml.data.location = src/test/xml/
 
jira.release.info = unknown
#
# If the browser path is set then when a test fails the func test framework will try and start
# the browser with a temporary file of captured web output.  if its not set then no harm
# and System.out will be used to dump the web response.
#
browser.path=firefox

Now our integration harness setup is complete and we can finally move on to the interesting stuff.

The Test Suite

Since we’re going to make use of the JiraWebTest, we are forced to use JUnit for the integration tests.
This requires us to create a JUnit Test Suite which is liste below.

Note: ALL integration tests must be in a test package that starts with it.[rest.of.package]

AllTests.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
package it.com.sysbliss.jira.plugins;
 
import junit.framework.Test;
import junit.framework.TestSuite;
 
public class AllTests {
 
    public static Test suite() {
	final TestSuite suite = new TestSuite("Integration Test for it.com.sysbliss.jira.plugins");
 
	suite.addTestSuite(ProjectsRestTest.class);
 
	return suite;
    }
 
}

What’s this JiraWebTest anyway?

JiraWebTest is a class provided by the jira-func-test package that should have been added to your pom.xml by the plugins SDK when you created the project.

It’s a class that your test classes can extend that provides extra functionality when running integration tests.
That extra functionality comes at a price though, like being forced to use JUnit… But wait, that’s not all! You can read an entire post about the pros and cons of the web test framework.

That being said, we are going to make as little use of this class as possible in hope something better comes along, however it does provide something very useful: The ability to load our exported test data.

And so, we’ll put up with it for now.

Finally, the integration test!

So here I’ll just proved the entire class and provide explanations after it.

ProjectsRestTest.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
package it.com.sysbliss.jira.plugins;
 
import java.io.ByteArrayInputStream;
import java.io.InputStream;
 
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
 
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.GenericType;
import com.sun.jersey.api.client.WebResource;
 
import com.atlassian.jira.webtests.JIRAWebTest;
import com.sysbliss.jira.plugins.rest.RestProject;
import com.sysbliss.jira.plugins.rest.RestProjects;
 
public class ProjectsRestTest extends JIRAWebTest {
 
    public ProjectsRestTest(final String name) {
	super(name);
    }
 
    @Override
    public void setUp() {
	super.setUp();
	restoreData("it-data.xml");
    }
 
    @Override
    public void tearDown() {
	super.tearDown();
    }
 
    public void testRestProjectsFound() throws Exception {
	final Client client = Client.create();
	final WebResource resource = client.resource("http://localhost:2990/jira/rest/projectversions/1.0/projects.xml");
 
	final List<RestProject> projects = resource.get(new GenericType<List<RestProject>>() {});
	assertEquals(2, projects.size());
    }
}

Extend JiraWebTest

line 18:
we simply extend JiraWebTest to give us our data loading functionality

line 21:
make sure you call super() !

lines 24-28:

  • override the setUp method
  • call super.setUp()
  • call restoreData(“it-data.xml”); – this loads our test data before each test

lines 30-33:
Make sure you override tearDown and call super.tearDown();

lines 36-37:

  • create a jersey Client
  • create a WebResource with our resource url

line 39:
Execute our GET request and cast the response to our model using the GenericType provided by jax-rs

line 40:
We can now use our model objects to assert that our request returned the 2 project objects we have in our test data.

Running the tests

whew, we’re finally ready to actually run the tests… plugins SDK anyone?

Drop out to a terminal in the project root and run:

atlas-integration-test

Sit back and enjoy as you watch the following whiz (well, maybe half-walk/half-jog) by you:

  • Project is compiled and unit tests are run
  • JIRA is started and the plugin is automatically deployed
  • admin logs into JIRA and imports our test data
  • we are welcomed to the Hotel California
  • framework verifys JIRA is ready to run the integration tests
  • The integration tests are run
  • JIRA shuts down

The crowd rejoices

Although this article is a bit verbose, once you set this up, doing it again for other projects is a breeze and the feeling you get seeing the “build successful” at the end never get old.

Hope this was helpful…

Share and Enjoy:
  • Digg
  • Facebook
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Slashdot
  • StumbleUpon

Build System Installer

Later this week I’ll be posting a full tutorial on setting up and using the sysbliss automated build system.

For now, you can download the repository installer and poke around if you wish.

To install, download and extract the tar.gz file.  Move the extracted contents to the webserver you wish to use for your repository and run ant -f sysbliss-repo-installer.xml

Just follow the prompts and your repo will be setup.

More on using the system later.

Download Sysbliss Repo Installer

Share and Enjoy:
  • Digg
  • Facebook
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Slashdot
  • StumbleUpon

Release Management with Atlassian Bamboo and Jira

UPDATE
SysBliss recently release the Bamboo Release Management Plugin.
It replaces the “JIRA Versions” plugin and streamlines this entire process.
check it out: http://www.sysbliss.com/bamboo-release-management-plugin

begin old content
I recently released a new plugin for Atlassian Bamboo called Jira Versions.
In combination with Jira, the Bamboo Tagger Plugin and the Pre/Post Build Command Plugin it can be used as a complete release management system.

This post serves both as a quick tutorial on setting up bamboo as a release management system as well as a scenario that illustrates how the plugins can be used within a release workflow.

Scenario

Project Information

In our scenario, we will be building a fictitious web app project.
This project will be using an iterative/agile development process.
We will have:

  • 3 development iterations
  • 2 release candidates
  • 1 production release
  • 1 emergency bugfix release.

Bamboo Project Information:

Project Name Web Apps
Project Key WEB
Plan Name My Web App
Plan Key MYAPP

Deployment

Since we’re building a webapp, we need to deployment workflow for when and where different builds get deployed.
Figure A. shows our logical deployment workflow. The actual physical deployment all happens from the Bamboo server via shell scripts.

Figure A: Logical Release Deployment
Figure A. Logical Release Deployment

Versioning

Our project will use the following version number scheme:

[Major].[Minor].[Bugfix]-[type][iteration]-[build]

Major the major release number
Minor new features backwards compatible
Bugfix maintenance fixes / emergency
type release level i.e. dev, rc, prod
iteration iteration number
build bamboo build key / number

Using this scheme, our project will produce the following final version numbers (with multiple build versions in-between)

  • 1.0.0-dev1 – development iteration 1
  • 1.0.0-dev2 – development iteration 2
  • 1.0.0-dev3 – development iteration 3
  • 1.0.0-rc1 – release candidate 1
  • 1.0.0-rc2 – release candidate 2
  • 1.0.0 – first production release
  • 1.0.1 – emergency production bugfix release

Installation

Installation is simple….
Assuming you already have Jira and Bamboo installed and running:

Just download the 3 distrubution jars from the respective plugin pages and drop them into your ${BAMBOO_INSTALL}/webapp/WEB-INF/lib folder.

now just restart bamboo.

Project Setup

Version Your Package

Most software built today is compiled and packaged with some sort of automated tool. I’m sure there are a few die-hards that are still using vi and javac on the command-line but for the rest of us not living in the eighties, we’re using something like ant, maven, etc.

To that end, the jiraversions plugin was written to be compatible with almost every automated builder known today. This is accomplished by the use of parameters that can be passed to the builder of choice via the command-line. (how that gets done will be discussed shortly).

So the first thing we need to do is setup our build script to figure out which version it’s building and use it as part of the package name.

note: for simplicity’s sake, I’m going to use Ant in the examples, but the same method can be applied to anything that can run via a command line. I’m also going to use java as the language of choice, but again, bamboo and the plugins mentioned in this post can be used to build anything.

Assuming you already have targets that compile and jar up your project, we just need to add a target that gets the current version for the build and sets it as a property that can be used to append to the name of your jar file.

Essentially this target is here to handle builds done on a local developer’s machine.
It’s saying that if version.name was not passed on the commandline (or set some other way) then set default version properties.
The most interesting property is the version.name which will be set to the user’s username and a timestamp.
i.e. if I do a build on my local machine, the version will look something like: jdoklovic-2008-Aug-01_130923

Now we need to make sure that our final artifact is named properly. Usually you’ll have some sort of package target that handles spitting out the final artifact.
In our case the packaging looks like this:

        <!-- add the rest of the war task specifics here -->

So there are a few things going on here.
First, we have a target called package that simply depends on a target called create-war.

Although this isn’t really neccessary, it’s useful to have common target names across multiple projects. So if I had another project that creates a jar or a zip file, you would simply adjust the depends on the package target in that project. This way the lazy developers can always rely on running the package target regardless of what it actually spits out.

Next we have our create-war target.
This target depends on a compile target (which aptly named, compiles our project) and the get-version target we defined previously.
When it creates the war, it uses the ant project name and the version.name as the name of the war file. (real exciting, huh?)

Finally we have a target called auto-build.
I include this target in any of my ant files that will be called from Bamboo. Again, this just makes it simpler to setup in bamboo since you don’t need to think about which target to run.
This target can do anything you want it to and in my example I’ve included the bare minimum that I usually need a build to do…..

  • checkbamboo – this simply checks that ${user.name} is equal to the name of the user that bamboo runs as, and fails if it doesn’t.
  • test – runs unit tests and generates reports
  • package – runs our package target
  • publish – publishes our artifact to our dependency management system (i.e. apache ivy, a maven repo, what have you)

Some may wonder why the checkbamboo target exists and if it’s really useful. Although it’s very easy to get around, it’s there as a sanity check when developers are doing builds on their local machines and ensures that a developer does not accidentally publish a locally built artifact to the repository.

Obviously this is not a real and/or complete build file. It’s simply here to illustrate a basic outline of what’s needed for the automation to work.

Got Versions?

Our next order of business is to get versions setup in Jira.

There’s nothing special here….  simply create a Jira Project, go into the manage versions screen and add the proper versions.
Make sure all of the versions start out as Unreleased and are in the proper order. Bamboo will use the order provided by Jira to determine the latest version.

For our scenario, I’ve setup a Jira Project named “My Web App” with the key WEBMYAPP

My versions initially end up looking like this: (note: waiting to add the bugfix version till later)
manage versions

On To Bamboo

The last part of the setup is to configure our project in Bamboo. I’ve already setup my project with the Project Info listed at the beginning of this post, and have tied it to version control (specifically subversion).

Now it’s time to start configuring the JiraVersions plugin. The first screen we need is in the Configuration > Builder tab. Naviagte to there and click Edit Plan.

In the main Builder configuration, select Ant as your builder and put build.xml in the Build File box.
Now in the Target box, let’s add our build target and pass the version properties our build is expecting:

autobuild -Dversion.name=${bamboo.custom.jiraversion.name} -Dversion.released=${bamboo.custom.jiraversion.released} -Dversion.type=${bamboo.custom.jiraversion.type}

Our builder ends up looking something like:

builder configuration

Scrolling down on this same screen, click the “Enable Jira Versions” checkbox and the Jira Versions options will appear.

General Settings
First we need to let Bamboo know where to find our Jira Project by giving it the Jira Project key. You can click the test button to see if it Bamboo can find the project in the Jira server.

Next, set the Default Version Strategy to “Current Unreleased Version”. This tells Bamboo to ask Jira for the current unreleased version during “normal” operation. We’ll see how to override this later for a single build.

The Null Version strategy tells Bamboo what to do if Jira either has no versions setup, or none of the versions are unreleased (resulting in a null version returned).

The best idea is to set this value to “Skip and Pass Build” which will mark the build as successful but not actually build anything.

note: if we set it to fail the build, then builds that are fully released will fail just because there are no open/unreleased versions which might cause unwanted results in your project dependency chain.

In the future, you’ll have even more options…. (BJVER-6).

Now we can setup our version appenders. These let you append any string on to the version name before it gets expanded by any other fields. In our scenario, we’re going to append the full Bamboo build key (including the number) to the end of unreleased version names.

To do this, set the Unreleased Appender field to: -${bamboo.buildResultKey}
We’ll just leave the released appender field blank.

Version Types

The version types section allows you to add keywords that will be searched for in the version name and used as the type of release.
The searching uses a similar algorithm as the php version_compare function.

In our scenario we just need to setup dev and rc keywords.

We’re now done configuring the Builder section, so we can click the save button at the bottom of the screen and move on to the Post Actions tab.

Post Build Commands

Uner the Post Build Commands in the Post Actions tab, we need to add a Success Command.

This will be the absolute path on the Bamboo server to the shell script that will be responsible for deploying our app to the various servers.

We will setup the script to accept the properties set by the JiraVersions plugin as well as the Bamboo build result key so we need to pass them to the script here.

/opt/bamboo/deploy-scripts/deploy-webapp.sh -n ${bamboo.custom.jiraversion.name} -r ${bamboo.custom.jiraversion.released} -t ${bamboo.custom.jiraversion.type} -k ${bamboo.buildResultKey}

Tagging

Below the Post Build Commands, we can enable the Jira Versions Tagger which will allow us to make tags in our scm system based on some parameters.

In our scenario, we only want to tag successful builds, and since we’re using subversion, we’ll need to tell Bamboo where the tags should be made.

Finally, we only want Bamboo to tag Released versions of each version type.

That’s it for the configuration. Just one more thing to do before we get to the workflow:

Create the Deploy Script

Our deploy script will be responsible for figuring out which environment(s) to deploy to based on the input parameters. The deploy worflow image at the beginning of this post shows what gets deployed to where.

Create a file in the same path as we defined in the post build command. In our case, we will create: /opt/bamboo/deploy-scripts/deploy-webapp.sh

It should contain something similar to the following code:

#!/bin/bash
 
# parameter examples:
#  -n 1.2.0-dev1
#  -r false
#  -t dev
#  -k MY-WEBAPP-3
 
set -x
 
version=""
release=""
version_type=""
build_key=""
release_env=""
 
mypath=`dirname "$0"`
 
DEV_ENV="dev.mydomain.com"
QA_ENV="qa.mydomain.com"
BUG_ENV="bugfix.mydomain.com"
STAGE_ENV="staging.mydomain.com"
 
BAMBOO_HOME="/opt/bamboo/bamboo-home"
dist_dir="$BAMBOO_HOME/xml-data/build-dir/WEB-MYAPP/dist"
 
# ~~~~~~~~~~~~~~~~
#   Functions
#
# ~~~~~~~~~~~~~~~~
 
usage(){
 
   cat &lt;

Go With The Flow

Now that everything is setup, we’re ready to go through the basic development cycle workflow.

This is pretty straight forward with only a few things to watch out for…..

So let’s get started. Per our versions, we’re starting with iteration 1 of our webapp project.

Generally, we will be adding new features in our iterations based on User Stories that are entered into Jira.

As we close out Jira issues and commit code, Bamboo will build our unreleased dev1 version for us.

We can check the status of all version builds by going to the Jira Versions tab for our build plan. After the first checkin, the Jira Versions will look somethin like the following:

After our iteration is finished, it’s time to release dev1. This is a 2 step process.

First, go into the manage versions screen in Jira and click the release link next to the 1.0.0-dev1 version.

Second, go to the Jira Versions tab in Bamboo. We will now see the released dev1 version with a link that will let us do a manual build.

We need to kick off the build manually because Bamboo is now going to be building the un-released dev2 version when code commits happen. Thus, it is important to do this manual build as soon as you release the version in Jira to make sure that no commits happen after the release.

At this point, we just follow this same process for all of our iterations. When we are ready to release the final iteration version, we need to do one extra step: merge the dev versions into the first release candidate.

Merging will do a couple of things for us. It will allow users to see everything that has been included in the release candidate. It will also remove the merged version from the Jira Versions tab in Bamboo.  This makes it impossible for someone to accidentally re-build an already released dev version.

You can still get to the old builds by going to the Completed Builds tab in bamboo.

To merge, you simply use the merge links in the Manage Versions section of Jira.

Once our iterations are complete and we move on to the first release candidate, the workflow remains the same… commit, Babmoo builds, release when ready.

When we reach the point of releasing the final release candidate, we again need to merge. This time we will merge all of the rc versions into the production version. From here, we just go along the workflow as normal and release the production version when ready.

Throughout the development cycles, you shee see the following:

  • Builds appearing in the Jira Versions tab
  • Un-released versions being deployed to the development server.
  • Released versions being deployed to the development and QA servers
  • Released versions being tagged in subversion
  • Un-released Production builds being deployed to the bugfix server
  • Released Production build deployed to the staging server.

If everything is good to go on the staging server, we can then manually deploy it to the actual production server. This is left as a manual process just to ensure that a human is watching the process and making sure it goes ok.

Finally, if there are emergency bugs that need to be fixed in production without a full development cycle, we can simply add a new version in Jira called 1.0.1

From there, we just do the normal process of committing code, releasing when ready, manually building the released version and manually deploying from staging to production.

And there you have it. However, there’s more……

Beware of Null Versions
We have our build set to pass with success if there are no versions returned from Jira. This is useful for dependency builds that need to complete within a larger build tree, however, this means a new development rule must be followed:

No code should be committed to a project without an unreleased version.

If code is committed, bamboo will see the change in the scm and try to run a build, but since no version will be returned by Jira, it will simply do nothing but look successful.  This is not the optimal scenario and BJVER-6 aims to make this a little more fool proof.

It’s also a good idea to create a subversion commit hook that checks Jira for an unreleased version and fails the commit if it doesn’t find one.

I will post a link to the subversion pre-commit hook once I get it finished.

I hope this post was helpful.

Share and Enjoy:
  • Digg
  • Facebook
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Slashdot
  • StumbleUpon