-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheduler-slack-publisher.sh
executable file
·125 lines (112 loc) · 2.75 KB
/
scheduler-slack-publisher.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
# include the common functions
source "commons.sh"
# prepare git
prepare_git
if [[ ${BITBUCKET_EXIT_CODE} -eq 0 ]]; then
echo "Job execution is ok for ${BITBUCKET_REPO_FULL_NAME}."
exit 0
fi
if [ "$#" -ne 1 ]; then
echo "Illegal number of parameters"
exit 1
fi
if [ "$1" == "owasp-dependency-check" ]; then
## building slack message
SLACK_MESSAGE="{\
\"blocks\": [\
{\
\"type\": \"section\",\
\"block_id\": \"section\",\
\"text\": {\
\"type\": \"mrkdwn\",\
\"text\": \":x: ${BITBUCKET_REPO_SLUG} :x: \n OWASP Dependency check failed for ${BITBUCKET_REPO_SLUG} - build ${BITBUCKET_BUILD_NUMBER}\"\
}\
},\
{\
\"type\": \"actions\",\
\"elements\": [\
{\
\"type\": \"button\",\
\"text\": {\
\"type\": \"plain_text\",\
\"text\": \"Go to Build\",\
},\
\"url\": \"${BITBUCKET_GIT_HTTP_ORIGIN}/addon/pipelines/home#!/results/${BITBUCKET_BUILD_NUMBER}\"\
},\
{\
\"type\": \"button\",\
\"text\": {\
\"type\": \"plain_text\",\
\"text\": \"Download Report\",\
},\
\"url\": \"https://vlaamseoverheid.jfrog.io/artifactory/magda-owasp/${BITBUCKET_REPO_SLUG}/${BITBUCKET_REPO_SLUG}-${BITBUCKET_BUILD_NUMBER}-$(date +%Y%m%d).html\"\
}\
]\
}\
]\
}"
## send slack message
curl -d "$SLACK_MESSAGE" -H "Content-Type: application/json" -X POST ${SLACK_WEBHOOK_URL_OWASP}
elif [ "$1" == "update-dependencies" ]; then
## building slack message
SLACK_MESSAGE="{\
\"blocks\": [\
{\
\"type\": \"section\",\
\"block_id\": \"section\",\
\"text\": {\
\"type\": \"mrkdwn\",\
\"text\": \":x: ${BITBUCKET_REPO_SLUG} :x: \n Update dependencies failed for ${BITBUCKET_REPO_SLUG} - build ${BITBUCKET_BUILD_NUMBER}\"\
}\
},\
{\
\"type\": \"actions\",\
\"elements\": [\
{\
\"type\": \"button\",\
\"text\": {\
\"type\": \"plain_text\",\
\"text\": \"Go to Build\",\
},\
\"url\": \"${BITBUCKET_GIT_HTTP_ORIGIN}/addon/pipelines/home#!/results/${BITBUCKET_BUILD_NUMBER}\"\
}\
]\
}\
]\
}"
## send slack message
curl -d "$SLACK_MESSAGE" -H "Content-Type: application/json" -X POST ${SLACK_WEBHOOK_URL_UPDATEDEPENDENCIES}
elif [ "$1" == "stable-develop-check" ]; then
## building slack message
SLACK_MESSAGE="{\
\"blocks\": [\
{\
\"type\": \"section\",\
\"block_id\": \"section\",\
\"text\": {\
\"type\": \"mrkdwn\",\
\"text\": \":x: ${BITBUCKET_REPO_SLUG} :x: \n Develop branch is unstable: ${BITBUCKET_REPO_SLUG} - build ${BITBUCKET_BUILD_NUMBER}\"\
}\
},\
{\
\"type\": \"actions\",\
\"elements\": [\
{\
\"type\": \"button\",\
\"text\": {\
\"type\": \"plain_text\",\
\"text\": \"Go to Build\",\
},\
\"url\": \"${BITBUCKET_GIT_HTTP_ORIGIN}/addon/pipelines/home#!/results/${BITBUCKET_BUILD_NUMBER}\"\
}\
]\
}\
]\
}"
## send slack message
curl -d "$SLACK_MESSAGE" -H "Content-Type: application/json" -X POST ${SLACK_WEBHOOK_URL_DEVELOPSTABLE}
else
echo "Invalid argument passed to identify job type."
exit 1
fi