Hatchbox post deploy script for Discord

Send deployment notifications to Discord after each deploy on Hatchbox.

Environment Variables

Add these to your Hatchbox environment:

Variable What it is
DISCORD_DEPLOY_WEBHOOK_URL Your Discord webhook URL
DISCORD_DEPLOY_APP_NAME Your app name (for the notification title)

The Script

Create a bin/post_deploy file in your Rails app:

#!/bin/bash

REVISION_SHORT="${REVISION:0:7}"
DEPLOY_TIME="$(TZ=America/New_York date '+%b %-d, %Y %I:%M:%S %p ET')"

curl -X POST -H "Content-Type: application/json" \
-d "{
  \"content\": \"🚀 **${DISCORD_DEPLOY_APP_NAME} deployed**\n\n**Branch:** \`${BRANCH}\`\n**Commit:** \`${REVISION_SHORT}\`\n**Release:** \`${RELEASE}\`\n**Roles:** \`${ROLES}\`\n**Log ID:** \`${LOG_ID}\`\n**Time:** ${DEPLOY_TIME}\"
}" \
"$DISCORD_DEPLOY_WEBHOOK_URL"

Make it executable:

chmod +x bin/post_deploy

Add to Hatchbox

In your Hatchbox app configuration, add bin/post_deploy to the post-deploy scripts.

Hatchbox provides these environment variables:

  • BRANCH - The git branch being deployed
  • REVISION - The full git commit SHA
  • RELEASE - The release number
  • ROLES - The server roles (e.g., web, worker)
  • LOG_ID - The deployment log ID

The script formats the commit SHA to 7 characters and timestamps it in Eastern Time.