Merge pull request #11323 from owncloud/matrix-notification
[full-ci]send build notification to matrix
This commit is contained in:
2 files changed
+38
-17
No files matched your search
+8
-17
@@ -35,7 +35,6 @@ PLUGINS_GIT_ACTION = "plugins/git-action:1"
|
||||
PLUGINS_MANIFEST = "plugins/manifest:1"
|
||||
PLUGINS_S3 = "plugins/s3:1"
|
||||
PLUGINS_S3_CACHE = "plugins/s3-cache:1"
|
||||
PLUGINS_SLACK = "plugins/slack:1"
|
||||
REDIS = "redis:6-alpine"
|
||||
SONARSOURCE_SONAR_SCANNER_CLI = "sonarsource/sonar-scanner-cli:11.0"
|
||||
|
||||
@@ -332,11 +331,6 @@ config = {
|
||||
"tikaNeeded": True,
|
||||
},
|
||||
},
|
||||
"rocketchat": {
|
||||
"channel": "builds",
|
||||
"channel_cron": "builds",
|
||||
"from_secret": "rocketchat_talk_webhook",
|
||||
},
|
||||
"binaryReleases": {
|
||||
"os": ["linux", "darwin"],
|
||||
},
|
||||
@@ -2351,28 +2345,25 @@ def makeGoGenerate(module):
|
||||
|
||||
def notify(ctx):
|
||||
status = ["failure"]
|
||||
channel = config["rocketchat"]["channel"]
|
||||
if ctx.build.event == "cron":
|
||||
status.append("success")
|
||||
channel = config["rocketchat"]["channel_cron"]
|
||||
|
||||
return {
|
||||
"kind": "pipeline",
|
||||
"type": "docker",
|
||||
"name": "chat-notifications",
|
||||
"clone": {
|
||||
"disable": True,
|
||||
},
|
||||
"steps": [
|
||||
{
|
||||
"name": "notify-rocketchat",
|
||||
"image": PLUGINS_SLACK,
|
||||
"settings": {
|
||||
"webhook": {
|
||||
"from_secret": config["rocketchat"]["from_secret"],
|
||||
"name": "notify-matrix",
|
||||
"image": OC_CI_ALPINE,
|
||||
"environment": {
|
||||
"MATRIX_TOKEN": {
|
||||
"from_secret": "matrix_token",
|
||||
},
|
||||
"channel": channel,
|
||||
},
|
||||
"commands": [
|
||||
"bash %s/tests/config/drone/notification.sh" % (dirs["base"]),
|
||||
],
|
||||
},
|
||||
],
|
||||
"depends_on": [],
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
COMMIT_SHA_SHORT=${DRONE_COMMIT:0:8}
|
||||
BUILD_STATUS="✅ Success"
|
||||
ROOMID="!rnWsCVUmDHDJbiSPMM:matrix.org"
|
||||
|
||||
|
||||
if [ ${DRONE_BUILD_STATUS} == "failure" ]; then
|
||||
BUILD_STATUS="❌️ Failure"
|
||||
fi
|
||||
|
||||
message_html='<b>'$BUILD_STATUS'</b> <a href="'${DRONE_BUILD_LINK}'">'${DRONE_REPO}'#'$COMMIT_SHA_SHORT'</a> ('${DRONE_BRANCH}') by <b>'${DRONE_COMMIT_AUTHOR}'</b>'
|
||||
message_html=$(echo "$message_html" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g')
|
||||
|
||||
response=$(curl -s -o /dev/null -X PUT -w "%{http_code}" 'https://matrix.org/_matrix/client/v3/rooms/'$ROOMID'/send/m.room.message/'$(date +%s) \
|
||||
-H "Authorization: Bearer "$MATRIX_TOKEN \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{
|
||||
"msgtype": "m.text",
|
||||
"body": "'"$message_html"'",
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": "'"$message_html"'"
|
||||
}')
|
||||
|
||||
if [ $status_code != 200 ]; then
|
||||
echo "❌ Error: failed sending notification to matrix"
|
||||
exit 1
|
||||
fi
|
||||
Reference in new issue
Block a user