Sample Webhook Listeners

Below are some sample Webhook Listener use cases and how to implement them.

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