Last active
June 29, 2017 17:35
-
-
Save ijin/29d37b12d6f3f5ff4405622d3c7cf036 to your computer and use it in GitHub Desktop.
Deploy with pm2 and notify via slack
This file contains hidden or 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/bash | |
set -x | |
export SHA1=`echo ${CIRCLE_SHA1} | cut -c1-7` | |
export ENV=`echo $1 | rev | cut -d \- -f1 | rev` | |
pm2 deploy ./app/config/deploy/deploy.json $1 update --force | |
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://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/300/PKpktytKH9.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://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/300/PKpktytKH9.png" | |
export EXIT=1 | |
fi | |
curl -X POST --data-urlencode 'payload={"username": "pm2 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