Skip to content

Commit

Permalink
SLCORE-705: Slack notification on pipeline failure (#879)
Browse files Browse the repository at this point in the history
* SLCORE-705: Slack notification on pipeline failure

* Fix script invocation
  • Loading branch information
thahnen authored Mar 11, 2024
1 parent 419bb87 commit b4d71f2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:

Check warning on line 86 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L86

task "test_linux" depends on task "build", but their only_if conditions are different

Check warning on line 86 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L86

task "test_linux" depends on task "build", but their only_if conditions are different
# Run unit tests on Linux with Java 17 and SonarQube analysis on Next
Expand All @@ -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:

Check warning on line 108 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L108

task "test_windows" depends on task "build", but their only_if conditions are different

Check warning on line 108 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L108

task "test_windows" depends on task "build", but their only_if conditions are different
# Run UTs on Windows (Java 17)
Expand All @@ -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:

Check warning on line 131 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L131

task "mend_scan" depends on task "build", but their only_if conditions are different

Check warning on line 131 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L131

task "mend_scan" depends on task "build", but their only_if conditions are different
# Run Mend analysis
Expand All @@ -141,6 +149,9 @@ mend_scan_task:
always:
ws_artifacts:
path: "whitesource/**/*"
on_failure:
slack_notification_script: |
.cirrus/slack-notification.sh
qa_task:

Check warning on line 156 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L156

task "qa" depends on task "build", but their only_if conditions are different

Check warning on line 156 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L156

task "qa" depends on task "build", but their only_if conditions are different

Check warning on line 156 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L156

task "qa" depends on task "build", but their only_if conditions are different

Check warning on line 156 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L156

task "qa" depends on task "build", but their only_if conditions are different

Check warning on line 156 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L156

task "qa" depends on task "build", but their only_if conditions are different

Check warning on line 156 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L156

task "qa" depends on task "build", but their only_if conditions are different

Check warning on line 156 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L156

task "qa" depends on task "build", but their only_if conditions are different

Check warning on line 156 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L156

task "qa" depends on task "build", but their only_if conditions are different

Check warning on line 156 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L156

task "qa" depends on task "build", but their only_if conditions are different

Check warning on line 156 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L156

task "qa" depends on task "build", but their only_if conditions are different
# Run ITs
Expand Down Expand Up @@ -200,6 +211,8 @@ qa_task:
format: junit
log_artifacts:
path: "**/target/**/sonarqube*/logs/*.log"
slack_notification_script: |
.cirrus/slack-notification.sh
promote_task:

Check warning on line 217 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L217

task "promote" depends on task "build", but their only_if conditions are different

Check warning on line 217 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L217

task "promote" depends on task "mend_scan", but their only_if conditions are different

Check warning on line 217 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L217

task "promote" depends on task "build", but their only_if conditions are different

Check warning on line 217 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L217

task "promote" depends on task "mend_scan", but their only_if conditions are different
# Promotion
Expand All @@ -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
28 changes: 28 additions & 0 deletions .cirrus/slack-notification.sh
Original file line number Diff line number Diff line change
@@ -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 @- <<EOF
{
"channel": "squad-sonar-solution-bots",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Cirrus CI build failure on pipeline"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Task <https://cirrus-ci.com/task/$CIRRUS_TASK_ID|$CIRRUS_TASK_ID> failed on *<$CIRRUS_REPO_CLONE_URL|$CIRRUS_REPO_FULL_NAME>* ($CIRRUS_BRANCH)"
}
}
]
}
EOF

0 comments on commit b4d71f2

Please sign in to comment.