Versions Compared


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



The below script is posting the initial message to slack and subsequently replying to that message with the plugin logs. If you only wish to send the initial message you can stop after line 15


titleFailed Workflow Notification Script
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 = "Failed Workflow Notification";"Running listener: ${listenerName}");

def channel = '


def slackAccountCode = 'SLACK';

//make the workflow complete message and include error data
def message = SLACK.makeWorkflowCompletedMessage(EVENT.payload,true);

//save the tsId so we can reply with the failed logs
def tsId = SLACK.postMessage(slackAccountCode,channel,message);

LOG.setMessage("Posted slack message ${tsId}");

//now get our failed plugin logs and attach them
def streams = FLEXDEPLOY.


if(!streams || streams.size() == 0) {

def errorStream = streams.last();

//now attach the logs to our previous message
SLACK.postAttachment(slackAccountCode,channel,errorStream,'Failed logs',tsId);

LOG.setMessage("Posted slack message ${tsId} with logs");

As stated before you will need to add your Slack account prior to using this listener.


We now have a Webhook Listener that will send a Slack notification to our specified channel every time a workflow is completed. In order to only send the notification when the workflow execution has failed we will need to implement a filter. The filter is groovy script that will determine whether or not our Listener will process a given event. To edit the filter we will need to click the filter tab to the left of our script tab. We will now create a groovy script that will return true when we want our listener to process the event and false otherwise.



titleFailed Workflow Notification Filter
Code Block
def excludedProjects = [795341];

return !"SUCCESS".equals(EVENT.payload.executionStatus) && !excludedProjects.contains(EVENT.payload.project.projectId);

In this example we have also added a list of excluded projects that we do not want our listener to process even if the workflow execution has failed. The return value will check our event payload for the execution status. If the execution status is SUCCESS, or if the project Id of the workflow execution is in our excluded projects list we will return false. You can edit this filter to cater to your needs. For example, you can edit the return statement to only return true only if the workflow was a deployment and it failed when trying to deploy to Production.


Now that we have our Webhook Listener completely set up we will create a workflow that will fail and attempt to execute it. In order to see if our filter is working correctly we will view our event messages after executing our faulty workflow. This can be found by clicking the Event Outgoing Webhook Messages button on the main events page.