Created
May 28, 2015 14:44
-
-
Save gdoumergue/b8bb2a3faa2d6079deda to your computer and use it in GitHub Desktop.
shell script to send slack notifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
send_slack() { | |
if [ -z "${SLACK_TOKEN}" ];then | |
echo "function send_slack needs SLACK_TOKEN variable. Add a new integration to slack." | |
exit 1 | |
fi | |
if [ -z "${1}" ];then | |
echo "No text to send ? Are you kidding me ?" | |
exit 1 | |
fi | |
[ -z "${SLACK_CHAN}" ] && SLACK_CHAN="#tests" | |
[ -z "${SLACK_USERNAME}" ] && SLACK_USERNAME=YOURBOT | |
[ -z "${SLACK_ICON}" ] && SLACK_ICON=":postal_horn:" | |
URL=https://YOURSLACKACCOUNT.slack.com/services/hooks/incoming-webhook?token=${SLACK_TOKEN} | |
curl -X POST --data-urlencode 'payload={"channel": "'${SLACK_CHAN}'", "username": "'${SLACK_USERNAME}'", "text": "'"${*}"'", "icon_emoji": "'${SLACK_ICON}'"}' ${URL} > /dev/null 2>&1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment