-
Notifications
You must be signed in to change notification settings - Fork 31
/
slackNotify.groovy
31 lines (31 loc) · 1004 Bytes
/
slackNotify.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import groovy.json.JsonOutput
def call(title, text, color, hookurl, channel, actions=[]) {
def jenkinsIcon = 'https://wiki.jenkins-ci.org/download/attachments/2916393/logo.png'
def slackURL = hookurl
def payloadJson = [
channel: channel,
username: "Jenkins",
icon_url: jenkinsIcon,
attachments: [[
fallback: text,
color: color,
author_name: env.CHANGE_AUTHOR_DISPLAY_NAME,
fields: [
[
title: title,
value: text,
short: false
],
[
title: "Change Summary",
value: env.CHANGE_TITLE,
short: false
]
],
actions:actions
]]
]
def encodedReq = URLEncoder.encode(JsonOutput.toJson(payloadJson), "UTF-8")
sh("curl -s -S -X POST " +
"--data \'payload=${encodedReq}\' ${slackURL}")
}