ci: add slack notfications

This sends a message to a slack channel if a scheduled pipeline is
ran and reports either failure or success.
This commit is contained in:
Jakub Rusz 2021-07-09 13:40:34 +02:00 committed by Alexander Todorov
parent 2b99e9e894
commit 0b962c9185
3 changed files with 32 additions and 1 deletions

View file

@ -236,6 +236,25 @@ API:
INTERNAL_NETWORK: ["true"]
DISTRO_CODE: ["rhel_90"]
NIGHTLY_FAIL:
stage: finish
tags:
- shell
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: on_failure
script:
- schutzbot/slack_notification.sh FAILED ":big-sad:"
NIGHTLY_SUCCESS:
stage: finish
tags:
- shell
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
script:
- schutzbot/slack_notification.sh SUCCESS ":partymeow:"
# Installer:
# stage: test
# extends: .terraform

12
schutzbot/slack_notification.sh Executable file
View file

@ -0,0 +1,12 @@
#!/bin/bash
set -eux
COMPOSE_ID=$(cat COMPOSE_ID)
MESSAGE="\"Nightly pipeline execution on *$COMPOSE_ID* finished with status *$1* $2 \n Link to results: $CI_PIPELINE_URL \""
curl \
-X POST \
-H 'Content-type: application/json' \
--data '{"text": "test", "blocks": [ { "type": "section", "text": {"type": "mrkdwn", "text":'"$MESSAGE"'}}]}' \
"$SLACK_WEBHOOK_URL"

View file

@ -8,7 +8,7 @@ COMPOSE_ID=$(cat COMPOSE_ID)
COMPOSE_URL="${COMPOSE_URL:-http://download.devel.redhat.com/rhel-8/nightly/RHEL-8/$COMPOSE_ID}"
# in case COMPOSE_URL was defined from the outside refresh COMPOSE_ID file,
# used for telegram messages in case of success/failure
# used for slack messages in case of success/failure
curl -L "$COMPOSE_URL/COMPOSE_ID" > COMPOSE_ID
# Make sure the compose URL really exists