Hi,
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 :
@NotNull
@Override
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 : https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-access-build-variables-from-a-bamboo-task/qaq-p/572570,
taskContext.getBuildContext().getBuildNumber();
but there is no way of getting the taskContext.
Any ideas ?
Thanks !