Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How to access build variables from a bamboo Notification



I'm trying to develop a new Bamboo Notification Plugin.

According to the official documentation - if I want to create my special Notification, in which I want to add a log file as attachment to my email, for example, I need to implement the following interface ExtendedNotification.  

This interface has a method that need to be implemented. The problem is getting the build version from the context in this method to try to attach the correct log file (for example - \BAMBOO\tools\logs\${bamboo.planKey}\health_${bamboo.buildNumber}.txt). 

My code is below : 

public Email updateEmail (@NotNull Email email) {
try {

//VariableContext variables = taskContext.getBuildContext ().getVariableContext ();

// E:\Atlassian\BAMBOO\tools\logs\${bamboo.planKey}\health_${bamboo.buildNumber}.txt
File logFile = new File ("E:\\Atlassian\\BAMBOO\\tools\\logs\\" + taskContext.getBuildContext().getPlanKey () + "\\health_" + taskContext.getBuildContext().getBuildNumber() + ".txt");

//Message message = new MimeMessage(session);
Multipart multipart = new MimeMultipart ();

// creates body part for the message
MimeBodyPart messageBodyPart = new MimeBodyPart ();
messageBodyPart.setContent (getHtmlEmailContent (), "text/html");

// creates body part for the attachment
MimeBodyPart attachPart = new MimeBodyPart ();

// code to add attachment...will be revealed later
attachPart.attachFile (logFile);

// adds parts to the multipart
multipart.addBodyPart (messageBodyPart);
multipart.addBodyPart (attachPart);

// sets the multipart as message's content
email.setMultipart (multipart);
} catch (Exception e) {
log.error ("There was a problem composing the email", e);
return null;
return email;

I tried to follow the guidelines provided here :,


but there is no way of getting the taskContext. 

Any ideas ?

Thanks !

1 answer

As I posted this question in stackoverflow, this is the answer : 

Finally, I found the way to make it work.

Those variable I want to get, the planKey and the buildNumber are coming from the following :

public class MyNotification extends AbstractCompletedNotification implements ExtendedNotification {
    private ResultsSummary resultsSummary;
    private ImmutablePlan plan;

    public Email updateEmail (@NotNull Email email) {
        try {

            File logFile = new File ("E:\\Atlassian\\BAMBOO\\tools\\logs\\" + 
                plan.getPlanKey () + 
                "\\health_" + 
                resultsSummary.getBuildNumber() + 

And the plan and the resultSummary are set in the MyNotificationEventListener when I create my custom notification - MyNotification :

public class MyNotificationEventListener {
    public void handleEvent (@NotNull Object event) {
        if (event instanceof ChainCompletedEvent) { // for example
            MyNotification myNotification = (MyNotification) BambooNotificationUtils.createNotification (MyNotification.class);
            myNotification.setResultsSummary (this.resultsSummaryManager.getResultsSummary (chainCompletedEvent.getPlanResultKey ()));
            ImmutablePlan immutablePlan = this.planManager.getPlanByKey (chainCompletedEvent.getPlanKey ());
            myNotification.setPlan (immutablePlan);

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bamboo

Bamboo Data Center on Kubernetes

Hi, If you are running self-managed environments and looking to adopt modern infrastructure, Bamboo Data Center can now be deployed in a Kubernetes cluster. By leveraging Kubernetes, you can easily...

943 views 3 8
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you