Getting Started with Outgoing Webhooks

This guide will walk through everything needed in order to send a slack notification on workflow failures.

Configuring Slack integration

You will first need to configure your Slack integration with FlexDeploy. To do this you will need to create a new Slack bot and create a FlexDeploy Messaging Account for Slack. To get more information on this you can follow the guide located on our Slack plugin guide. This simple configuration will allow you to send notifications to your specified Slack channel for this bot.

We will want to create a new Messaging Account for Slack. We can do this by going to Topology→ Integrations → Messaging. For the Slack provider, the only required property is the Bot Token.

Creating an Outgoing Webhook Listener

Now that Slack is integrated with FlexDeploy we will now want to create the Webhook Listener that will process all failed Workflow Completed events. To do this we will navigate to the events screen through Administration → Integrations → Outgoing Webhooks. To create a new Webhook Listener click the Create Listener button.

Add a name, event type, and mock payload to the new event listener. Also remove the default script implementation. The event type will specify what events our new listener will process, in this case the Workflow Completed event type. The mock payload is used in the groovy script editor to give suggestions when accessing the EVENT variable. Set this to the Workflow Completed payload.

Implement the Groovy Script

Now with the Webhook Listener created, we can add the groovy script to send the Slack message. FlexDeploy has several built in Webhook Context Variables and Methods that can be used to help you implement exactly what you want in this groovy script. We will be using FlexDeploy’s Slack methods in order to send a notification.

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

 

//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"; LOG.info("Running listener: ${listenerName}"); def channel = 'testing'; 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.getPluginLogInputStreams(EVENT.payload.workflowExecutionId); if(!streams || streams.size() == 0) { return; }