Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sync to S3 and notify via Slack
#!/bin/bash
set -x
export SHA1=`echo ${CIRCLE_SHA1} | cut -c1-7`
# 引数で配布先のbucketを分けたい
if [ $#$ -ne 1 ]; then
export SL_COLOR="danger"
export SL_TEXT="Sync failure: Not enough args in CircleCI: $S3 - ${CIRCLE_BRANCH} (<${CIRCLE_COMPARE_URL}|${SHA1}>) by ${CIRCLE_USERNAME} !!"
export SL_ICON="http://cdn.dev.classmethod.jp/wp-content/uploads/2014/05/aws_icon-s3_white-200x200.png"
export EXIT=1
fi
export STAGE=`echo $1`
export S3_BUCKET="${STAGE}.${DOMAIN}"
aws --region $REGION s3 sync ./dist/ s3://$S3_BUCKET/ --delete
if [ $? -eq 0 ]; then
export SL_COLOR="good"
export SL_TEXT="Sync success: $S3 - ${CIRCLE_BRANCH} (<${CIRCLE_COMPARE_URL}|${SHA1}>) by ${CIRCLE_USERNAME} !!"
export SL_ICON="http://cdn.dev.classmethod.jp/wp-content/uploads/2014/05/aws_icon-s3_white-200x200.png"
export EXIT=0
else
export SL_COLOR="danger"
export SL_TEXT="Sync failure: $S3 - ${CIRCLE_BRANCH} (<${CIRCLE_COMPARE_URL}|${SHA1}>) by ${CIRCLE_USERNAME} !!"
export SL_ICON="http://cdn.dev.classmethod.jp/wp-content/uploads/2014/05/aws_icon-s3_white-200x200.png"
export EXIT=1
fi
curl -X POST --data-urlencode 'payload={"username": "S3", "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
You can’t perform that action at this time.