Introduction to writing Tasks
Bamboo 3.1 and later
Create a new plugin
- First download the copy of the latest Plugin SDK and install it on your machine.
atlas-create-bamboo-pluginfrom the command line.
- When asked for the groupId, artifactId and package just enter "myfirstplugin" and leave the other options as the defaults.
Writing your first Task
Create a new class called "MyFirstTask" in the "myfirstplugin" package and implement the interface TaskType on the MyFirstTask class. Change your class so it looks like the one below.
What am I looking at?
A TaskType is the minimal requirement for implementing a Task. This is where all your plugins heavy lifting happens and all Tasks must be capable of running on a Remote Agent.
In our example we are getting the provided BuildLogger from the TaskContext and writing the string "Hello, World!" to the log. Of course, Tasks that you can develop can be a lot more complex than this one.
A TaskContext gives contextual information about where and how the Task is being executed. From this object it is possible to obtain a reference to the configuration, build log, working directory and information about the Job executing from the BuildContext.
TaskResult and TaskResultBuilder
To let Bamboo know if your Task has completed successfully or otherwise, you need to pass back a TaskResult instance. To facilitate the creation of a TaskResult we have provided the TaskResultBuilder. The TaskResultBuilder uses the Builder Pattern to create and maintain the TaskResult.
For example if the local variable
condition is true the TaskResult calculated when build() is called will be Successful even though we initially set it to Failed.
Registering your Task with the plugin system
In the atlassian-plugin.xml between the
atlassian-plugin elements, simply add the following:
This lets the Plugin system know what the name of the Task, its description, key and class in order for it to be used in side of Bamboo. For more information about the Task descriptor see The Task Type Module Definition.
Running the 'MyFirstTask' Plugin
From inside your project execute on the command line
atlas-run. This command will compile your plugin, run its tests and start Bamboo with your plugin installed. You can tell when Bamboo has finished loading when you see the following in the logs:
Checking that your plugin has loaded correctly
Browse to http://localhost:6990/bamboo then go to Administration->System->Plugins and you should see your plugin in the list of User Installed plugins
Run your Task
Create a new plan, 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!"