import flexagon.ff.adfext.common.model.pojosmodel2.pojo.communication.EmailAttachment;
import groovy.json.JsonOutput;
//Carry out any custom action you wish for this event. Check out the documentation for reference or ideas.
//Optionally filter out events you dont want to execute by returning false on the filter script tab.
def listenerName = "Email Failed Logs";
LOG.info("Running listener: ${listenerName}");
//retrieve plugin log input stream map
def logs = FLEXDEPLOY.getPluginLogInputStreams(EVENT.payload.workflowExecutionId);
def attachments = [];
//for each entry create and add a new attachment
//prior to 5.4.0.1 logs would be a list instead of a map
logs.each { log ->
attachments.add(new EmailAttachment(log.value,"${log.key}.txt","text/plain"));
}
LOG.info("Sending email with ${attachments.size()} attachments.");
//send email
def subject = "${EVENT.payload.project.projectName} failed in ${EVENT.payload.environment.environmentName}";
def message = JsonOutput.prettyPrint(JsonOutput.toJson(EVENT.payload));
def recipients = ["my.user@domain.com"];
EMAIL.sendEmail(subject, message, recipients, attachments);
LOG.setMessage("Sent email message to ${recipients}"); |