diff --git a/README.md b/README.md index f50971b..8ad75a9 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,10 @@ Requests OpenShift to start build from the specified build config and waits for Runs the OWASP dependency-check tool. +### rocketSend + +Sends message to the specified WebHook. + ## Groovy source files ### DockerHub diff --git a/vars/rocketSend.groovy b/vars/rocketSend.groovy new file mode 100644 index 0000000..ec24ba4 --- /dev/null +++ b/vars/rocketSend.groovy @@ -0,0 +1,22 @@ +def void call(String webHook, String message, String avatar = null, Boolean rawMessage = true) { + Map data = [:] as Map + data['text'] = message + data['rawMessage'] = rawMessage + + if (avatar != null) { + data['avatar'] = avatar + } + + def curlCommand = 'curl ' + + ' -X POST "' + webHook + '" ' + + ' -H "Content-Type: application/json" ' + + ' --data \'' + groovy.json.JsonOutput.toJson(data) + '\' ' + + def returnCode = sh(script: curlCommand, returnStatus: true) + + if (returnCode != 0) { + error("RocketChat notification failed!") + } else { + echo "RocketChat notification sent successfully" + } +} \ No newline at end of file diff --git a/vars/rocketSend.txt b/vars/rocketSend.txt new file mode 100644 index 0000000..77cb054 --- /dev/null +++ b/vars/rocketSend.txt @@ -0,0 +1,34 @@ + +

+ Part of @Library('jenkins-pipeline-shared-libraries') +

+
+
+ rocketSend(webHook:String, message:String, avatar:String=null, rawMessage:Boolean=true):void +
+
+

+ Publish message at chat.puzzle.ch. The channel destination is disabled for the integration. Therefore you need to create the Webhook first. +
+ Example call: +
+ rocketSend("https://chat.puzzle.ch/hooks/../..", "Build Successful", "https://chat.puzzle.ch/emoji-custom/success.png", true) +

+ +
+
+ +