Skip to content

Commit 58b39a7

Browse files
authored
Adding Slack notification section
1 parent 3b91d05 commit 58b39a7

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

main.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,28 @@ fi
6161

6262
git commit -m "Rolling image $IMAGE_NAME to Deployment $NAMESPACE:deployment/$DOCKER_IMAGE"
6363
git push
64+
65+
# bonus : notify the right Slack channel regarding the namespace you are deploying to (example for two namespaces called "dev" and "prod")
66+
if [[ "$NAMESPACE" == "dev" ]] || [[ "$NAMESPACE" == "prod" ]]; then
67+
68+
if [[ "$NAMESPACE" == "dev" ]]; then
69+
SLACK_CHANNEL=${SLACK_DEV_CHANNEL_ID}
70+
else
71+
SLACK_CHANNEL=${SLACK_PROD_CHANNEL_ID}
72+
fi
73+
74+
# this is the syntax for a Gitlab pipeline, but you get the idea : basically you can build the perfect message that fits your needs
75+
COMMIT_URL="$CI_PROJECT_URL/-/commit/$CI_COMMIT_SHA"
76+
COMMIT_MESSAGE_CLEANED=$(echo "${CI_COMMIT_MESSAGE}" | tr '"' "'")
77+
78+
BODY="{\"channel\":\"${SLACK_CHANNEL}\",
79+
\"username\":\"gitops-deploy\",
80+
\"text\":\"*${SERVICE_NAME}* has been released including this <${COMMIT_URL}|commit>\",
81+
\"icon_emoji\":\":rocket:\",
82+
\"attachments\":[{\"blocks\":[{\"type\":\"context\",\"elements\":[{\"type\":\"plain_text\",\"text\":\"${COMMIT_MESSAGE_CLEANED}\",\"emoji\":false}]}]}]
83+
}";
84+
85+
echo "Calling Slack API: https://slack.com/api/chat.postMessage with BODY: $BODY"
86+
curl -X POST "https://slack.com/api/chat.postMessage" -H "Authorization: Bearer ${SLACK_APP_TOKEN}" -H "Content-type: application/json" --data "$BODY"
87+
88+
fi

0 commit comments

Comments
 (0)