Plugin development in Bamboo using Atlassian SDK [Part - 2]
In Part -1 of the article we discussed about Bamboo and its installation on Windows.
Now let us understand what Atlassian Plugin SDK is and how it can be setup and used for plugin development in Bamboo.
Atlassian Plugin SDK
Using the Atlassian plugin software developer kit (SDK), you can create apps to extend Atlassian server applications like Jira Software, Jira Service Desk, Confluence, Bitbucket Server, and Bamboo.
Atlassian Plugin SDK provides a set of shell scripts for creating, installing and building plugins for Atlassian products.
By the end of this article, you will have set-up a development environment and create a basic plugin for Bamboo.
Installation of SDK
To install the SDK, you will need JDK and JAVA_HOME path variable set. This is already covered in Part -1.
Follow the steps as mentioned below:
- Download the latest version of SDK here
- Locate the downloaded file and double-click the launcher (.exe)
- Follow the prompts to install the SDK
Verification of SDK
Open a command-prompt and run the following command
atlas-version
In addition, you will need your favorite editor or development IDE like Eclipse or Visual Studio Code and Maven setup in your machine.
With your IDE and Maven setup, you have the local development environment configured for Atlassian SDK and you're ready to build your first plugin !
Let us follow a step-by-step process with a total of 6 steps for creation and verification of the plugin:
Step 1: Create a new plugin
Open a command-prompt, navigate to the directory where you want to create your plugin and run the command atlas-create-bamboo-plugin as shown below.
C:/Users/<current-user>/workspace>atlas-create-bamboo-plugin
When asked for groupId, artifactId and package, enter "myfirstplugin" and leave other options as defaults.
Step 2: Writing your first Task
- Launch your IDE and open the project created in Step 1 above
- Inside package 'myfirstplugin', create a new class called 'MyFirstTask' (myfirstplugin/src/main/java/myfirstplugin)
- Change your class 'MyFirstTask' so it looks like the one below
package myfirstplugin;
import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.task.TaskContext;
import com.atlassian.bamboo.task.TaskException;
import com.atlassian.bamboo.task.TaskResult;
import com.atlassian.bamboo.task.TaskResultBuilder;
import com.atlassian.bamboo.task.TaskType;
public class MyFirstTask implements TaskType
{
@Override
public TaskResult execute(final TaskContext taskContext) throws TaskException
{
final BuildLogger buildLogger = taskContext.getBuildLogger();
buildLogger.addBuildLogEntry("Hello, World!");
return TaskResultBuilder.newBuilder(taskContext).success().build();
}
}
Step 3: Registering your task with plugin system
In the atlassian-plugin.xml of your project, add the following code between the atlassian-plugin elements tag
<TaskType key="myFirstTask" name="My First Task" class="myfirstplugin.MyFirstTask"> <description>A task that prints 'Hello, World!'</description>
</taskType>
In Steps 2 and 3 above, we have utilized Tasks plugin module of Bamboo. This module allows to add new Tasks to Bamboo. For more information click here.
Step 4: Running 'MyFirstTask' plugin
Open a command-prompt, navigate to your project and execute the command line atlas-run. This will compile your plugin, run its tests, and start Bamboo with your plugin installed.
C:/Users/<current-user>/workspace/myfirstplugin>atlas-run
You can confirm that Bamboo has finished loaded and started when you see the following in logs. Make a note of Bamboo URL shown in the logs below.
[WARNING] [talledLocalContainer] June 06, 2020 12:26:54 PM org.apache.catalina.startup.Catalina start [WARNING] [talledLocalContainer] INFO: Server startup in 40924 ms [INFO] [talledLocalContainer] Tomcat 6.x started on port [6990] [INFO] bamboo started successfully and available at http://localhost:6990/bamboo
[INFO] Type CTRL-C to exit
[Optional] Step 4: Alternative way of running the plugin
You can use atlas-package command to package the plugin artifact and generate a JAR file. Open a command-prompt and run the command atlas-package as shown below.
C:/Users/<current-user>/workspace/myfirstplugin>atlas-package
Navigate to Bamboo Administration -> Manage apps -> Click on Upload app -> Select the JAR file (generated in target folder of the project).
Step 5: Check if your plugin is loaded correctly
Browse to http://localhost:6990/bamboo then go to Administration -> System -> Plugins. You should see the plugin in the list of User installed plugins.
Note: Default port of Bamboo on Windows is 8085, however when bamboo is run using atlas-run command (step 4 above), notice that Bamboo listens on port 6990.
Step 6: Run your Task
Create a new plan in Bamboo, select your task "My First Task" from the list of Tasks and add it to the default job and run the plan.
In the job logs, you should see the task output, "Hello, World!"
You can further customize your plugin as per the requirement. For more details refer the official documentation available here
Source code of this project is available here
To summarize, below are the sections covered in each part of the article.
- Installation of Bamboo - covered in Part 1
- Installation of Atlassian SDK - covered in Part 2
- Creation of Plugin for Bamboo - covered in Part 2
Happy Learning !!!