forked from stac-utils/titiler-pgstac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slacknotify.sh
54 lines (44 loc) · 1.64 KB
/
slacknotify.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash
set -euo pipefail
SLACK_WEBHOOK=${SLACK_WEBHOOK}
ENVIRONMENT="${CI_ENVIRONMENT_NAME:=common_environment}"
function print_slack_summary() {
local slack_msg_header
local slack_msg_body
# Populate header and define slack channels
slack_msg_header=":x: Deploy of ${CI_PROJECT_TITLE} to ${ENVIRONMENT} failed"
if [[ "${CI_JOB_STATUS}" == "success" ]]; then
slack_msg_header=":white_check_mark: Deploy of ${CI_PROJECT_TITLE} to ${ENVIRONMENT} succeeded"
fi
# Populate slack message body
slack_msg_body="${CI_JOB_NAME} with job id <${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}|${CI_JOB_ID}> by ${GITLAB_USER_NAME} \n<${CI_PROJECT_URL}/-/commit/$(git rev-parse HEAD)|$(git rev-parse --short HEAD)> - ${CI_COMMIT_REF_NAME} "
cat <<-SLACK
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${slack_msg_header}"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${slack_msg_body}"
}
}
]
}
SLACK
}
function share_slack_update() {
curl -X POST \
--data-urlencode "payload=$(print_slack_summary)" \
"${SLACK_WEBHOOK}"
}
share_slack_update