Sample Webhook Listeners
Below are some sample Webhook Listener use cases and how to implement them.
- 1 The Default Listener (POST Webhook)
- 2 End Release After Snapshot Deploys to Production
- 3 Send a Slack Notification After Approval Task Is Created
- 4 Attach Failed Plugin Logs to Jira Issue
- 5 Create ServiceNow Incident on Workflow Failure
- 6 Send Test Results to Teams
- 7 Build Dependent FlexDeploy Project
- 8 Send email with logs on Workflow Failed
- 9 Create Teams Approval Tasks
- 10 Execute Utility Project
- 11 Update Package to Completed After Production Deployment
- 12 Set the Assignee of the Work Item on Work Item Creation
- 13 Enable Webhook on Project Creation
The Default Listener (POST Webhook)
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.
//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
Note that this function may no longer needed as Release Settings incorporate this functionality.
To take advantage of ending a release after a pipeline execution completes you can create a new listener and select the Pipeline Stage Completed. You will then need to check whether the completed stage is the final stage in the pipeline. You can do this in a number of ways. One way is shown below by checking the environment code and comparing it to our final PROD stage.
Example Groovy Code
//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 = "endReleaseListener";
LOG.info("Running listener: ${listenerName}");
if(EVENT.payload.environment.environmentCode.equals("PROD")){
LOG.setMessage("Release ${EVENT.payload.release.releaseNam