Skip to content

Instantly share code, notes, and snippets.

@neutraltone
Last active March 14, 2018 16:13
Show Gist options
  • Save neutraltone/7b384eedbc6dc3bd66107b3378daf39f to your computer and use it in GitHub Desktop.
Save neutraltone/7b384eedbc6dc3bd66107b3378daf39f to your computer and use it in GitHub Desktop.
Slack Deploy Message Script

Setup

Add a new incoming webhook to Slack. This will give you a webhook URL complete with a token. You should also select a channel to default post to.

# Post to Slack
SHA=$(git rev-parse --verify HEAD)
MSG=$(git log -1 --pretty=format:'%s')
AUTHOR=$(git log -1 --pretty=format:'%an')
BRANCH=$(git branch | grep \* | cut -d ' ' -f2)
FALLBACKMSG="https://github.com/<USERNAME>/<REPO>/commit/$SHA deployed to <WEBSITE-URL>"
URLMSG="<https://github.com/<USERNAME>/<REPO>/commit/$SHA|$MSG>"
SHAMSG="<https://github.com/<USERNAME>/<REPO>/commit/$SHA|$SHA>"
curl -X POST --data-urlencode 'payload={"username": "Forge", "icon_emoji": ":shipit:", "attachments": [{"fallback": "'"$FALLBACKMSG"'", "color": "good", "fields": [{"title": "Deployed", "value": "'"$URLMSG"'", "short": true},{"title": "Author", "value": "'"$AUTHOR"'", "short": true},{"title": "Branch", "value": "'"$BRANCH"'", "short": true},{"title": "Website", "value": "<WEBSITE-URL>", "short": true},{"title": "SHA", "value": "'"$SHAMSG"'"}]}]}' <WEBHOOK-URL>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment