Using Listeners in ScriptRunner for Bamboo, you can perform custom actions whenever standard Bamboo system events are fired. There are built-in listeners, or you can create a custom listener.
Adding a Listener
Navigate to Admin > Listeners.
Select the Add New Item button to expand the listeners available to create.
Choose a Custom Listener or a built-in listener.
You can create custom listeners with your own scripts. To add a custom listener, follow these steps:
Select Custom Listener.
In the Events field, select the events you want to listen for.
The event is contained in the script binding. The event object has the type corresponding to its name. For example, if you are listening for BuildCompletedEvent you get a
You may choose to have your listener look for multiple events. If you need to do different things depending on the type of event, you can check that with
Alternatively, you can type your event to the most specific superclass. In in the above example that would be
For example, to get the page content for both
def event = event as BuildEvent(1) def content = event.content.bodyAsString // do something with the page content
eventis passed in the binding. This line is only used to give type information when using an IDE, and has no functional impact
In addition to custom listeners, there are built-in ones to help save you time on more commonly used listeners.
Conditional Job Killer
This listener allows you to specify a condition to stop a build. You can stop any job that you want for any reason. Write in your condition, and then every job that runs is checked against it.
Follow these steps to set up a Conditional Job Killer:
When you get to the point of choosing a listener, select Conditional Job Killer.
The Conditional Job Killer form appears:
Enter a Note for your your listener.
This helps identify it in the list of listeners.
Enter your scripted condition in the Condition field.
A value of
truestops a build and a value of
falseallows the build to proceed.
This has the capacity to stop every build in Bamboo. If you only enter
true, it would stop all builds. If your condition only applies to a subset of builds/plans/etc, make sure that is accounted for in your condition.
Enter a custom error message in the Error Message field.
This message appears on the job when it is stopped by this listener.This helps you identify when a job was stopped by this listener.
Have questions? Visit the Atlassian Community to connect, share, and learn with other Atlassian users and experts, including Adaptavist staff.
Want to learn more? Check out courses on Adaptavist Learn, an online platform to onboard and train new users for Atlassian solutions.