Skip to content

Instantly share code, notes, and snippets.

@ijin
Last active June 26, 2017 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ijin/5815c8c9dfec778ee11e582e3a0f0edd to your computer and use it in GitHub Desktop.
Save ijin/5815c8c9dfec778ee11e582e3a0f0edd to your computer and use it in GitHub Desktop.
echo_and_notify_sh
#!/bin/bash
set -x
export SHA1=`echo ${CIRCLE_SHA1} | cut -c1-7`
export ENV=`echo $1 | rev | cut -d \- -f1 | rev`
echo "hi"
if [ $? -eq 0 ]; then
export SL_COLOR="good"
export SL_TEXT="Success: Deployed ${CIRCLE_BRANCH} (<${CIRCLE_COMPARE_URL}|${SHA1}>) by ${CIRCLE_USERNAME} !!"
export SL_ICON="https://a.slack-edge.com/bda7/plugins/circleci/assets/service_512.png"
export EXIT=0
else
export SL_COLOR="danger"
export SL_TEXT="Failure: Deploying ${CIRCLE_BRANCH} (<${CIRCLE_COMPARE_URL}|${SHA1}>) by ${CIRCLE_USERNAME} !!"
export SL_ICON="https://a.slack-edge.com/bda7/plugins/circleci/assets/service_512.png"
export EXIT=1
fi
curl -X POST --data-urlencode 'payload={"username": "CircleCI Deployment ('"$CIRCLE_PROJECT_REPONAME"')", "icon_url": "'"$SL_ICON"'", "channel": "'"${CHANNEL:-#test}"'", "attachments": [{ "color": "'"$SL_COLOR"'", "text": "'"$SL_TEXT"'", "mrkdwn_in": ["text"] }] }' https://hooks.slack.com/services/${SLACK_HOOK}
exit $EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment