Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleEmail Failed Logs Script
Code Block
languagegroovy
import flexagon.ff.adfextmodel2.common.modelpojo.pojos.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}");

...

You may want to change a package’s status to completed to indicate it successfully deployed to its final environment. This webhook handles changing the status for you using the Workflow Completed Event. You could update the filter to only update the status for certain projects, releases, instances, etc. The listener also handles removing the package from its release first, as a package cannot be marked completed if it’s in an active release.

Expand
titleWebhook Listener
Code Block
languagegroovy
​def releaseName = EVENT.payload.release.releaseName
def projectId = EVENT.payload.project.projectId
def packageName = EVENT.payload.packageName

if (releaseName != null)
{
  FLEXDEPLOY.removeProjectsFromRelease(releaseName, [new flexagon.fd.model.pojos.rest.release.ReleaseProjectsPojo(projectId, packageName, false)])
}

FLEXDEPLOY.updatePackageStatus(projectId, packageName, "COMPLETED")

...