Skip to content
Snippets Groups Projects

ozg-7493 add send failure message

Merged Bastian Heppener requested to merge ozg-7493-add-matrix-notification into main
1 file
+ 34
30
Compare changes
  • Side-by-side
  • Inline
+ 34
30
 
/*
 
* Copyright (C) 2024 Das Land Schleswig-Holstein vertreten durch den
 
* Ministerpräsidenten des Landes Schleswig-Holstein
 
* Staatskanzlei
 
* Abteilung Digitalisierung und zentrales IT-Management der Landesregierung
 
*
 
* Lizenziert unter der EUPL, Version 1.2 oder - sobald
 
* diese von der Europäischen Kommission genehmigt wurden -
 
* Folgeversionen der EUPL ("Lizenz");
 
* Sie dürfen dieses Werk ausschließlich gemäß
 
* dieser Lizenz nutzen.
 
* Eine Kopie der Lizenz finden Sie hier:
 
*
 
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
 
*
 
* Sofern nicht durch anwendbare Rechtsvorschriften
 
* gefordert oder in schriftlicher Form vereinbart, wird
 
* die unter der Lizenz verbreitete Software "so wie sie
 
* ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN -
 
* ausdrücklich oder stillschweigend - verbreitet.
 
* Die sprachspezifischen Genehmigungen und Beschränkungen
 
* unter der Lizenz sind dem Lizenztext zu entnehmen.
 
*/
 
@Library('ozgcloud-libs') _
 
pipeline {
pipeline {
agent {
agent {
node {
node {
@@ -6,6 +31,7 @@ pipeline {
@@ -6,6 +31,7 @@ pipeline {
}
}
environment {
environment {
 
PIPELINE_NAME = "Code-SH: info-manager-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 = ""
@@ -167,6 +193,7 @@ pipeline {
@@ -167,6 +193,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
@@ -182,7 +209,13 @@ pipeline {
@@ -182,7 +209,13 @@ pipeline {
}
}
}
}
}
}
post {
 
failure {
 
script {
 
sendMatrixMessage.sendFailureMessage(FAILED_STAGE)
 
}
 
}
 
}
}
}
@@ -234,35 +267,6 @@ String getBuildProfile() {
@@ -234,35 +267,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":"Info-Manager-Proxy: Build Failed. Stage: ${FAILED_STAGE} Build-ID: ${env.BUILD_NUMBER}", \
"format": "org.matrix.custom.html", \
"formatted_body":"Info-Manager-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"
Loading