Skip to content

Instantly share code, notes, and snippets.

@juno
Last active April 11, 2026 02:21
Show Gist options
  • Select an option

  • Save juno/0794765b31843a16fd579fac4b29af06 to your computer and use it in GitHub Desktop.

Select an option

Save juno/0794765b31843a16fd579fac4b29af06 to your computer and use it in GitHub Desktop.
Hatchbox.io Post Deploy Script for New Relic Releases
# --- Configuration ---
# If these are defined in Hatchbox Environment Variables, keep the variable names as is.
# Otherwise, replace them with your actual strings (e.g., "NRAK-...").
NR_API_KEY="${NEW_RELIC_API_KEY}"
NR_ENTITY_GUID="${NEW_RELIC_ENTITY_GUID}"
# 1. Get version information (Use REVISION file if available, otherwise use timestamp)
DEPLOY_VERSION=$(cat REVISION 2>/dev/null || date +%Y%m%d-%H%M%S)
# 2. Build GraphQL query
# Using a heredoc avoids complicated quote escaping in the shell.
read -r -d '' JSON_PAYLOAD <<EOF
{
"query": "mutation { changeTrackingCreateDeployment(deployment: {entityGuid: \"$NR_ENTITY_GUID\", version: \"$DEPLOY_VERSION\", user: \"Hatchbox\"}) { deploymentId } }"
}
EOF
# 3. Execute request to New Relic API
curl -s -X POST 'https://api.newrelic.com/graphql' \
-H "Api-Key: $NR_API_KEY" \
-H "Content-Type: application/json" \
--data "$JSON_PAYLOAD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment