...
When creating a new Listener, the script will default to the below which simply forwards the payload via a REST Post request. This script emulates an outbound webhook in the truest sense since no payload modification or logic is done. Simply update the postUrl variable with your endpoint and its ready to go.
...
Expand | ||
---|---|---|
| ||
Code Block | ||
| ||
//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 = "myListener";
LOG.info("Running listener: ${listenerName}");
def postUrl = "";
def responseCode = REST.forward(postUrl,EVENT);
LOG.setMessage("Message forwarded (${responseCode}) to ${postUrl}"); |
End Release After Snapshot Deploys to Production
...
This function is listening to the ‘Workflow Completed’ Event.
Expand | ||
---|---|---|
| ||
Code Block | ||
| ||
import flexagon.ff. adfextmodel2.common pojo.model.pojos communication.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}"); | ||
Expand | title |
Email Failed Logs Filter
Code Block | ||
---|---|---|
| ||
return EVENT.payload.executionStatus == 'FAILURE'; |
Create Teams Approval Tasks
...
This sample sends an interactive message to a Microsoft Teams channel that allows members of the channel to approve or reject an associated FlexDeploy task. As shown in this script, you can add conditions to handle sending to multiple different channels in one listener depending on some condition. (e.g. environment, pipeline, release, etc.) You could also apply similar logic to the webhook listener filter to customize when and where the Teams message should be sent.
...