Skip to content

Commit

Permalink
add rocketSend function
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasKoller committed Oct 27, 2023
1 parent 73e9ea0 commit 5f1b605
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
32 changes: 32 additions & 0 deletions vars/rocketSend.groovy
Original file line number Diff line number Diff line change
@@ -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"
}
}
37 changes: 37 additions & 0 deletions vars/rocketSend.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<p>
Part of <code>@Library('jenkins-pipeline-shared-libraries')</code>
</p>
<dl>
<dt>
<code id="rocketSend">rocketSend(webHook:String, message:String, channel:String=null, avatar:String=null, rawMessage:Boolean=true):void</code>
</dt>
<dd>
<p>
Publish message at chat.puzzle.ch
<br />
Example call:
<br>
<code>rocketSend("https://chat.puzzle.ch/hooks/../..", "Build Successful", "general", "https://chat.puzzle.ch/emoji-custom/success.png", true)</code>
</p>
<ul>
<li>
<b>webHook</b> - WebHook Url
</li>
<li>
<b>message</b> - Content of the Rocket Chat message
</li>
<li>
<b>channel</b> - Channel used in Rocket Chat
</li>
<li>
<b>avatar</b> - Avatar image used in Rocket Chat
</li>
<li>
<b>rawMessage</b> - Message should be sent as raw text
</li>
</ul>
</dd>
</dl>
<!-- vim: set ft=html : -->
<!-- code: set language=html : -->

0 comments on commit 5f1b605

Please sign in to comment.