Skip to content

Instantly share code, notes, and snippets.

@kieranajp
Last active March 1, 2016 15:15
Show Gist options
  • Save kieranajp/9ed6731b861ac9637716 to your computer and use it in GitHub Desktop.
Save kieranajp/9ed6731b861ac9637716 to your computer and use it in GitHub Desktop.
Slack webhook that can be run when a successful deploy happens (we run it through CodeShip CI)
#!/bin/bash
# Slack Info
webhook_url="" # Put your Slack webhook URL here
channel="#general"
# Deploy info
server="" # Staging, production etc.
check_url="" # Link within the message body
application_name="" # Name of your application
# Aesthetics
icon=":shipit:"
username="Shipitbot"
color="#439FE0"
thumb_url="https://avatars.githubusercontent.com/$CI_COMMITTER_USERNAME"
# Message body
text="$CI_COMMITTER_NAME deployed $application_name! <$check_url|Check everything works>!"
field1title="Deployed to:"
field1value="$server"
field2title="Branch deployed:"
field2value="$CI_BRANCH"
escapedText=$(echo $text | sed 's/"/\"/g' | sed "s/'/\'/g" )
json=$(cat <<EOF
{
"channel": "$channel",
"username": "$username",
"icon_emoji": "$icon",
"attachments": [{
"color": "$color",
"text": "$escapedText",
"thumb_url": "$thumb_url",
"fields": [{
"title": "$field1title",
"value": "$field1value",
"short": true
}, {
"title": "$field2title",
"value": "$field2value",
"short": true
}]
}]
}
EOF
)
curl -s -d "payload=$json" "$webhook_url"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment