From b4d71f200d85819033c29c237fb739eebd193230 Mon Sep 17 00:00:00 2001 From: Tobias Hahnen Date: Mon, 11 Mar 2024 10:49:26 +0100 Subject: [PATCH] SLCORE-705: Slack notification on pipeline failure (#879) * SLCORE-705: Slack notification on pipeline failure * Fix script invocation --- .cirrus.yml | 16 ++++++++++++++++ .cirrus/slack-notification.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 .cirrus/slack-notification.sh diff --git a/.cirrus.yml b/.cirrus.yml index 73b0f34b24..d8504071d7 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -11,6 +11,7 @@ env: BURGR_PASSWORD: VAULT[development/kv/data/burgr data.cirrus_password] SONAR_HOST_URL: VAULT[development/kv/data/next data.url] SONAR_TOKEN: VAULT[development/kv/data/next data.token] + SLACK_TOKEN: VAULT[development/kv/data/slack data.token] auto_cancellation: $CIRRUS_BRANCH != $CIRRUS_DEFAULT_BRANCH @@ -78,6 +79,9 @@ build_task: cache_script: - mvn -B -e -V -Pits dependency:go-offline # populate cache including ITs deps too cleanup_before_cache_script: cleanup_maven_repository + on_failure: + slack_notification_script: | + .cirrus/slack-notification.sh test_linux_task: # Run unit tests on Linux with Java 17 and SonarQube analysis on Next @@ -98,6 +102,8 @@ test_linux_task: junit_artifacts: path: '**/target/surefire-reports/TEST-*.xml' format: junit + slack_notification_script: | + .cirrus/slack-notification.sh test_windows_task: # Run UTs on Windows (Java 17) @@ -119,6 +125,8 @@ test_windows_task: junit_artifacts: path: '**/target/surefire-reports/TEST-*.xml' format: junit + slack_notification_script: | + .cirrus/slack-notification.sh mend_scan_task: # Run Mend analysis @@ -141,6 +149,9 @@ mend_scan_task: always: ws_artifacts: path: "whitesource/**/*" + on_failure: + slack_notification_script: | + .cirrus/slack-notification.sh qa_task: # Run ITs @@ -200,6 +211,8 @@ qa_task: format: junit log_artifacts: path: "**/target/**/sonarqube*/logs/*.log" + slack_notification_script: | + .cirrus/slack-notification.sh promote_task: # Promotion @@ -223,3 +236,6 @@ promote_task: <<: *MAVEN_CACHE_DEFINITION script: cirrus_promote_maven cleanup_before_cache_script: cleanup_maven_repository + on_failure: + slack_notification_script: | + .cirrus/slack-notification.sh diff --git a/.cirrus/slack-notification.sh b/.cirrus/slack-notification.sh new file mode 100755 index 0000000000..5671f9b86c --- /dev/null +++ b/.cirrus/slack-notification.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -euo pipefail + +curl -X POST https://slack.com/api/chat.postMessage \ + -H "Authorization: Bearer ${SLACK_TOKEN}" \ + -H 'Content-type: application/json; charset=utf-8' \ + --data-binary @- < failed on *<$CIRRUS_REPO_CLONE_URL|$CIRRUS_REPO_FULL_NAME>* ($CIRRUS_BRANCH)" + } + } + ] +} +EOF