Skip to content

Instantly share code, notes, and snippets.

@jkanclerz
Last active January 15, 2024 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkanclerz/43e0c33dc4667b2c736834472426a103 to your computer and use it in GitHub Desktop.
Save jkanclerz/43e0c33dc4667b2c736834472426a103 to your computer and use it in GitHub Desktop.
Slack's notify about deployment
#!/bin/bash
ENVIRONMENT=${ENVIRONMENT:-'STAGING'}
LINK=${LINK:-'https://your-link.local'}
JIRA=${JIRA:-'https://jira.local'}
SLACK_URL=${SLACK_URL:='https://hooks.slack.com/services/your-slack-url'}
USERNAME='Alf'
USER_ICON=':alf:'
CHANNEL=${CHANNEL:-'#testit'}
current_branch() {
git rev-parse --abbrev-ref HEAD
}
branches=`current_branch`
read -r -d '' message_template << EOM
{
"channel": "${CHANNEL}",
"username": "${USERNAME}",
"icon_emoji": "${USER_ICON}",
"attachments": [
{
"pretext": ":siren_green: Yeah!, deployment to *${ENVIRONMENT}* was done :siren_green:",
"fields": [
{
"title": ":rocket: Project",
"value": "${ENVIRONMENT}",
"short": true
},
{
"title": ":link: Link",
"value": "${LINK}",
"short": true
},
{
"title": ":house_buildings: Environment",
"value": "${ENVIRONMENT}",
"short": true
},
{
"title": ":scrum-master: Current Sprint",
"value": "<${JIRA}|JIRA P7S1>",
"short": true
}
],
"color": "#7CD197"
},
{
"title": ":palm_tree: deployed branch:",
"text": "\`\`\`${branches}\`\`\`",
"color": "#1960a4"
}
]
}
EOM
curl -X POST --data-urlencode "payload=${message_template}" ${SLACK_URL}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment