From 1f06e6f6c152807fa3b7e3b800e8791c4756faa9 Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Mon, 4 Jul 2022 10:27:20 +0200 Subject: [PATCH] OZG-2586 send failure message to element --- Jenkinsfile | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1ca0692ac2..5acdf4c5b7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -290,8 +290,8 @@ pipeline { post { failure { script { - if (env.BRANCH_NAME == 'master') { - slackSend(color: "danger", message: "Goofy: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <${BLUE_OCEAN_URL}|${env.BUILD_NUMBER}>") + if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'release') { + sendFailureMessage() } } } @@ -518,4 +518,27 @@ String getKeycloakAccessToken() { return token.access_token } +} + +Void sendFailureMessage() { + def room = '' + def data = """{"msgtype":"m.text", \ + "body":"Goofy: Build Failed. Stage: ${FAILED_STAGE} Build-ID: ${env.BUILD_NUMBER} Link: ${BLUE_OCEAN_URL}", \ + "format": "org.matrix.custom.html", \ + "formatted_body":"Goofy: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <a href='${BLUE_OCEAN_URL}'>${env.BUILD_NUMBER}</a>"}""" + + if (env.BRANCH_NAME == 'master') { + room = "!iQPAvQIiRwRpNOszjw:matrix.ozg-sh.de" + } + else if (env.BRANCH_NAME == 'release') { + room = "!oWZpUGTFsxkJIYNfYg:matrix.ozg-sh.de" + } + + sh "curl -XPOST -H 'authorization: Bearer ${getElementAccessToken()}' -d '${data}' https://matrix.ozg-sh.de/_matrix/client/v3/rooms/$room/send/m.room.message" +} + +String getElementAccessToken() { + withCredentials([string(credentialsId: 'element-login-json', variable: 'LOGIN_JSON')]) { + return readJSON ( text: sh (script: '''curl -XPOST -d \"$LOGIN_JSON\" https://matrix.ozg-sh.de/_matrix/client/v3/login''', returnStdout: true)).access_token + } } \ No newline at end of file -- GitLab