Skip to content
Snippets Groups Projects
Commit 318de4fb authored by Bastian's avatar Bastian
Browse files

ozg-7493 add send failure message

parent 05bb53a6
No related branches found
No related tags found
1 merge request!2ozg-7493 add send failure message
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen * Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
@Library('ozgcloud-libs') _
pipeline { pipeline {
agent { agent {
node { node {
...@@ -29,6 +32,7 @@ pipeline { ...@@ -29,6 +32,7 @@ pipeline {
} }
environment { environment {
PIPELINE_NAME = "Code-SH: fachstellen-proxy"
RELEASE_REGEX = /v\d+.\d+.\d+/ RELEASE_REGEX = /v\d+.\d+.\d+/
BETA_REGEX = /v\d+.\d+.\d+-beta.\d/ BETA_REGEX = /v\d+.\d+.\d+-beta.\d/
FAILED_STAGE = "" FAILED_STAGE = ""
...@@ -192,6 +196,7 @@ pipeline { ...@@ -192,6 +196,7 @@ pipeline {
} }
steps { steps {
script { script {
FAILED_STAGE = env.STAGE_NAME
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
sh ''' sh '''
go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@latest go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@latest
...@@ -207,6 +212,13 @@ pipeline { ...@@ -207,6 +212,13 @@ pipeline {
} }
} }
} }
post {
failure {
script {
sendMatrixMessage.sendFailureMessage(FAILED_STAGE)
}
}
}
} }
...@@ -238,35 +250,6 @@ String getBuildProfile() { ...@@ -238,35 +250,6 @@ String getBuildProfile() {
} }
} }
Void sendFailureMessage() {
def room = getRoom()
def data = getFailureData()
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 getFailureData() {
return """{"msgtype":"m.text", \
"body":"Fachstellen-Proxy: Build Failed. Stage: ${FAILED_STAGE} Build-ID: ${env.BUILD_NUMBER}", \
"format": "org.matrix.custom.html", \
"formatted_body":"Fachstellen-Proxy: Build Failed. Stage: ${FAILED_STAGE} Build-ID: ${env.BUILD_NUMBER}"}"""
}
String getRoom() {
if (isReleaseBranch()) {
return "!oWZpUGTFsxkJIYNfYg:matrix.ozg-sh.de"
} else {
return "!iQPAvQIiRwRpNOszjw:matrix.ozg-sh.de"
}
}
Void configureGit() { Void configureGit() {
def email = "jenkins@ozg-sh.de" def email = "jenkins@ozg-sh.de"
def name = "jenkins" def name = "jenkins"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment