Last active
January 15, 2024 16:33
-
-
Save jkanclerz/43e0c33dc4667b2c736834472426a103 to your computer and use it in GitHub Desktop.
Slack's notify about deployment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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