Skip to content

Commit

Permalink
Merge pull request #56 from puzzle/rocket-send
Browse files Browse the repository at this point in the history
add rocketSend function
  • Loading branch information
LukasKoller authored Oct 31, 2023
2 parents 780eafc + ab8a3b5 commit 2363d33
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions vars/rocketSend.groovy
Original file line number Diff line number Diff line change
@@ -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"
}
}
34 changes: 34 additions & 0 deletions vars/rocketSend.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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, avatar:String=null, rawMessage:Boolean=true):void</code>
</dt>
<dd>
<p>
Publish message at chat.puzzle.ch. The channel destination is disabled for the integration. Therefore you need to create the Webhook first.
<br />
Example call:
<br>
<code>rocketSend("https://chat.puzzle.ch/hooks/../..", "Build Successful", "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>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 2363d33

Please sign in to comment.