Incoming Webhooks are a simple way to post messages from Tugboat into Slack. Creating an Incoming Webhook gives you a unique URL to which you send a JSON payload with the message text and some options.
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
Create a Tugboat environment variable to
store your SLACK_WEBHOOK_URL
:
Use this snippet in your configuration file to communicate with Slack via the service you want to respond from.
services:
apache:
commands:
online:
# Send a slack notification if we're on a PR build
- |
if [ ! -z "${TUGBOAT_GITHUB_PR}" ]; then
PR_URL="https://github.com/$TUGBOAT_REPO/pull/$TUGBOAT_GITHUB_PR"
DASHBOARD_URL="https://dashboard.tugboatqa.com/$TUGBOAT_PREVIEW_ID"
MESSAGE="*Tugboat URL:* $TUGBOAT_SERVICE_URL\n*PR:* $PR_URL\n*Dashboard:* $DASHBOARD_URL"
curl -X POST --data-urlencode "payload={\"username\": \"Tugboat\", \"text\": \"$MESSAGE\", \":boat:\": \":tugboat_qa:\"}" "$SLACK_WEBHOOK_URL"
fi
Voila! You Slack integration will look like this: