Skip to content
Snippets Groups Projects
Commit 62e0ba28 authored by Martin's avatar Martin
Browse files

use external script for sending element message (due to incorrect roomId)

parent 9c1a8dea
Branches
Tags
No related merge requests found
@Library('ozgcloud-libs') _
pipeline { pipeline {
agent { agent {
node { node {
...@@ -136,37 +138,12 @@ pipeline { ...@@ -136,37 +138,12 @@ pipeline {
} }
failure { failure {
script { script {
if (isMainBranch() || env.BRANCH_NAME == 'release') { sendMatrixMessage.sendFailureMessage(FAILED_STAGE)
sendFailureMessage()
}
} }
} }
} }
} }
Void sendFailureMessage() {
def room = ''
def data = """{"msgtype":"m.text",
"body":"Document-Manager: Build Failed. Stage: ${FAILED_STAGE} Build-ID: ${env.BUILD_NUMBER} Link: ${JENKINS_URL}",
"format": "org.matrix.custom.html",
"formatted_body":"<h3>Document-Manager: Build Failed.</h3><b>Stage:</b> ${FAILED_STAGE}<br><b>Build-ID:</b> <a href='${JENKINS_URL}'>${env.BUILD_NUMBER}</a>"}"""
if (isMainBranch()) {
room = "!GjqhmouBtnDbwUkAjx: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
}
}
String getPomVersion(String pomFile){ String getPomVersion(String pomFile){
def pom = readMavenPom file: pomFile def pom = readMavenPom file: pomFile
...@@ -177,7 +154,3 @@ String getParentPomVersion(String filePath) { ...@@ -177,7 +154,3 @@ String getParentPomVersion(String filePath) {
def pom = readMavenPom file: filePath def pom = readMavenPom file: filePath
return pom.parent.version return pom.parent.version
} }
Boolean isMainBranch() {
return env.BRANCH_NAME == 'main'
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment