Atlassian Bamboo Tutorial: Java Web App Deployment with Bitbucket Repository

By Sruthy

By Sruthy

Sruthy, with her 10+ years of experience, is a dynamic professional who seamlessly blends her creative soul with technical prowess. With a Technical Degree in Graphics Design and Communications and a Bachelor’s Degree in Electronics and Communication, she brings a unique combination of artistic flair…

Learn about our editorial policies.
Updated March 7, 2024

Atlassian Bamboo 6.8: Deployment of a Java Web Application to Tomcat Application Server

This tutorial will showcase on the Bamboo concepts for Build and Deployment of a Java web application to the Tomcat application server with the source code committed in the Bitbucket repository.

Atlassian Bamboo is a Continuous Integration (CI) and Continuous Deployment (CD) software.

It helps to automate the BUILDS of your software application and release management by creating the continuous delivery pipeline.

You can refer to the Series of DevOps Tutorials for more information on the CI/CD concept.

Atlassian Bamboo Tutorial

Pre-Requisite

  • Bitbucket repository created and populated with a Java Maven Web Application.
  • JDK 1.8 installed on the Build machine.
  • Apache Maven installed on the Build machine and Maven Home/Path to the bin directory set.
  • Tomcat 7.x or 8.x or 9.x installed on the deployment machine.

Bitbucket Repository and CI/CD flow

Given below is created the bitbucket repository that contains a Java Maven web project and will be used in Bamboo for CI and CD activities.

bitbucket repository

The flow of CI/CD showcased here. The code is developed and committed to Bitbucket and built/deployed to various environments running on Tomcat app server using Bamboo.

flow of CI/CD

Installing and Configuring the Bamboo Server

To download, install and configure the Bamboo server in http://localhost:8085, please look at the online confluence page.

Configuring Application links with Bitbucket server

As we would be using the source code stored in the Bitbucket repository, we will need to provide and configure the Bitbucket server link in the Bamboo server.

Having logged in to Bamboo URL go to Administration -> Manage Apps -> Application Links. Add the Bitbucket server URL and click on the Create New Link. This will automatically create a reciprocal link in the Bitbucket server as well.

Bamboo Administration - Create New Link

Bitbucket Server view of application link is created in the Administration settings.

Administration settings

Once the application links are configured, the Bitbucket repositories will be available to be selected in the Bamboo project configuration.

Understanding Bamboo Concepts

As you have seen the flow for CI /CD in the previous section, Bamboo uses the concepts of Project, Plan, Stages, and Jobs to accomplish the activities of build and Deploy.

Project: Typically every project teams work on software delivery of multiple applications. The project created in Bamboo is for every application which the team works on.

In order to create a Bamboo project, login to the Bamboo URL and click on Create -> Create Project.

create a Bamboo project

Enter a name and description. Click on Save.

Project name and Description

Plan: As the project is created, the next step is to create a Plan. A Plan contains information about the version control repository. In this case, our Java Maven web project is stored in the Bitbucket. Few other details like Access control for the plan are also mentioned as a part of creating the Plan.

create a Plan

Click on Create Plan and enter the details as shown below. The Bitbucket repository to be linked to the plan is also available once both the tools are linked.

Configure Plan

Once the above details are entered, click on Configure plan.

Click on Create for now.

Click on Create a new plan

Click on Action -> Configure Plan once the plan is created. We will now proceed to create Stages and Tasks.

Plan for Maven project

The following Plan configuration screen that contains a Default Stage in which we will create the Job followed by the grouping of tasks within it comes up.

Plan configuration screen

Stage: All the plans created will initially contain a Default stage as shown in the above screen. Example: of a stage can be a Build stage or a Deploy stage. Each stage will contain its own job with the grouping of tasks which is the smallest level of work done for build or deploy.

The stages run sequentially and every stage must execute successfully before moving on to the next stage.

Jobs: Jobs contain one or more tasks which are run in parallel.

Tasks: Tasks are a part of a job. Example: Jobs could be a maven build or deploy to the Tomcat app server.

All of the above definitions can be put in the following diagram for execution within a plan and can be used as shown below.

execution within a plan

Configure Stage

In the Plan Configuration screen, Click on Actions -> Configure Stage to rename the definition.

rename the definition.

Configure stage

Modify the Stage name and click on Save. I would be creating only one stage for my Build and Deploy. Teams are free to create multiple stages to segregate the same. Before we create the jobs and tasks, we need to install a remote agent for build and deployment which is described in the next section.

Understanding Bamboo Agent

If you look at the CI/CD workflow in section 2, you will need to perform Build on a server specified and deploy the application on multiple different environments. Hence for the Bamboo server to identify and connect to this build & deploy machines and run specific jobs on it, we will need to run an Agent service on these machines.

In Bamboo, there are two types of Agent:

  • Local Agents run on the Bamboo server which in my view should not be used to a large extent due to load and performance issues of the Bamboo server.
  • Remote Agents run on the machines other than the Bamboo server.

Capabilities are then tagged to the Agents to run specific Jobs defined in the plan.

Install a remote agent

(i) From the Administration menu, select Overview and download the agent on the remote machine.

download the agent on the remote machine

(ii) Under Agents category click on Install remote agent.

Install remote agent

(iii) Download the Remote Agent JAR file and run the command as shown below.

Download the Remote Agent JAR file

By default, the data from version control will be downloaded to the UserHomeDirectory/bamboo-agent-home directory. In case a new directory needs to be specified then the option –Dbamboo.home=<New folder> can be used.

The command will be run as follows to install and enable the agent.

Command Run

install and enable the agent

The agent is now installed and we need to approve the agent. Go to the URL mentioned at the end of the window and approve the agent to be enabled.

approve the agent

The URL to be used is as follows as per the instructions in the above screen.

http://localhost:8085/admin/agent/viewAgents.action?focusUuid=68aa2fcc-af5a-4989-a30e-8c577adf1646&selectedTab=Agent+authentication

Select the remote agent and click on Approve Access.

Approve Access

The remote agent is now in an approved state and we can proceed to add capabilities such as build instructions to run Maven build etc.

add capabilities

The remote agent is now online and is shown in the TAB.

remote agent is online

Click on the agent to add a Maven capability which will be used later in the Plan.

add a Maven capability

Click on Add capability. As we will be performing a Maven build add as shown.

Add capability to remote agent

Click on Add. The capability is now added to the remote Agent.

Adding Build and Deploy stage/job/tasks

Back in the plan configuration screen, we will create the following 2 stages in a single plan.

Adding Build and Deploy Stage

#1) Create the Build Stage and rename the Default job to Maven build in the Job details TAB. Click Save.

Create the Build Stage and rename the Default job to Maven build

Click on the Tasks TAB and add the Maven build task.

Click on the Tasks TAB

Add the Maven build details like Goal and Working sub-directory as shown. Click on Save once done.

Add Maven build details

For this Job go to the Artifacts TAB and create an artifact definition to make the WAR file generated out of the Maven build to be available in the Deploy stage which will be created next. Click Create once done.

create artifact

create an artifact definition

#2) Click on Plan configuration and create a Deploy stage.

Plan configuration

In the Deploy Stage, add a job to deploy the war file to Tomcat. Click on Add job and select Create a new job.

Add job

Add a new job

Click on Create job. Click on this job to add a task. The default task Source Code Checkout can be deleted. Add the Deploy Tomcat task and configure the task.

Create a new job

Add the Deploy Tomcat task and configure the task.

Click Save. Go to the Artifacts TAB for this job and add the dependency which was created in the Build stage. Click on Create dependency.

Create dependency.

Click on Create dependency

Click on Create. The dependency is added to this job so that the WAR file will be successfully deployed.

Run Plan

So here comes the moment. As the plan is completely defined to perform Build and Deploy tasks, we can now Run the plan.

Click on Run -> Run Plan.

Run Plan.

The plan run is successful and the WAR file is deployed successfully to the Tomcat app server.

The plan run is successful

WAR file is deployed

Triggers and Permissions

Additionally, for the plan, we can add triggers for an automatic run of the plan without any manual intervention. Triggers include the following options.

In the Plan configuration click on Triggers -> Add Trigger

Add Trigger

The most preferred option would be to schedule the execution of the plan.

schedule the execution of the plan

Project level permissions can also be added in the Plan Configuration -> Permissions.

Permissions

Summary

In this tutorial, we have seen how Atlassian Bamboo can be used for CI/CD activities for a Maven Web application. The tool can be further configured to integrate with Sonarqube for code analysis, Artifactory to store version of the binaries, Ansible, etc.

Most importantly its seamless integration with Bitbucket is definitely simple and easier too. This tutorial will be a perfect guide for those who are learning CIC/CD for the first time using Atlassian tools.

Hope you enjoyed this informative tutorial on Atlassian Bamboo!!

Was this helpful?

Thanks for your feedback!

Leave a Comment