diff --git a/vars/rocketSend.groovy b/vars/rocketSend.groovy new file mode 100644 index 0000000..d2d9899 --- /dev/null +++ b/vars/rocketSend.groovy @@ -0,0 +1,32 @@ +final ROCKET_ALIAS = "Jenkins" + +def void call(String webHook, String message, String channel = null, String avatar = null, Boolean rawMessage = true) { + Map data = [:] as Map + data['alias'] = ROCKET_ALIAS + data['text'] = message + data['rawMessage'] = rawMessage + + if (channel != null) { + data['channel'] = channel + } + + if (avatar != null) { + data['avatar'] = avatar + } + + def returnCode = sh(returnStatus: true, script: + ''' + curl + -X POST "${webHook}" + -H "Content-Type: application/json" + --data "${groovy.json.JsonOutput.toJson(data)}" + --fail ' + ''' + ) + + 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..383b598 --- /dev/null +++ b/vars/rocketSend.txt @@ -0,0 +1,37 @@ + +

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

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

+ Publish message at chat.puzzle.ch +
+ Example call: +
+ rocketSend("https://chat.puzzle.ch/hooks/../..", "Build Successful", "general", "https://chat.puzzle.ch/emoji-custom/success.png", true) +

+ +
+
+ +