Custom Slack Notifications using Shell Script

We can setup custom slack notification with a shell script.

STEP 1 : Create the Slack App :

Create and configure an app in your Slack developer account at https://api.slack.com.

When you create the app, do the following:

1.) Name your app, assign it to a Workspace, and select Create App .

2.) Select Incoming Webhooks.

3.) Enable the Activate Incoming Webhooks slider.

4.) Click Add New Webhook to Workspace .

5.) From the resulting app settings, copy the Webhook URL to your clipboard.

STEP 2 : Configure Custom Notifications for Slack :

1.) Add a shell script step in your workflow.

2.) Add the the below in the script :

url=(https://hooks.slack.com/services/XXXXXXXXXXXX/XXXXXXXXXXXXXXX)

payload='
{
"text": "${service.name} - ${infra.name} - ${infra.kubernetes.infraId} - ${env.name} Deployed *${app.name} to ${infra.name}*",
"attachments": [
{
"author_name": "${deploymentTriggeredBy}",
"text": "Deployment text",
"color": "#00a3e0"
}
]
}'

curl -s -X POST -H "Content-type: application/json" -d "$payload" $url

url will have the Webhook URL which we copied in the last from Step 1 above.

Once we run the workflow we will get the notification in the slack.

3 Likes