-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.groovy
86 lines (80 loc) · 2.33 KB
/
test.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//import com.dtolabs.rundeck.plugins.notification.NotificationPlugin
import groovy.json.JsonOutput
def sendMessage(type, color, configuration, execution) {
//with no args, there is a "configuration" and an "execution" variable in the context
//sendMessage(type, color, configuration, execution)
adaptive_card_payload = JsonOutput.toJson([
type: "message",
attachments: [
[
contentType: "application/vnd.microsoft.card.adaptive",
contentUrl: null,
content: [
type: "AdaptiveCard",
version: "1.4",
body: [
[
type: "RichTextBlock",
inlines: [
[
type: "TextRun",
text: "[${type}] Rundeck Job Notification",
weight: "Bolder",
size: "Medium",
color: "${color}"
]
]
],
[
type: "TextBlock",
text: "Job project: ${execution.project}",
wrap: true
],
[
type: "TextBlock",
text: "Job name: ${execution.job.name}",
wrap: true
],
[
type: "TextBlock",
text: "Job id: ${execution.id}",
wrap: true
],
[
type: "TextBlock",
text: "Job status: ${execution.status}",
wrap: true
],
[
type: "TextBlock",
text: "Started at: ${execution.dateStarted}",
wrap: true
]
],
actions: [
[
type: "Action.OpenUrl",
title: "Seed job execution",
url: "${execution.href}"
]
]
]
]
]
])
return adaptive_card_payload
}
configuration = [
'webhook_url': '<URL HERE>'
]
execution = [
'id': 'xyz',
'project': 'projectx',
'status': 'succes',
'dateEnded': '2017-05-05'
]
type = "START"
color = "Accent" // "Accent" or "Good" or "Warning" or "Attention"
adaptive_card_payload = sendMessage(type, color, configuration, execution)
process = [ 'bash', '-c', "curl -v -k -X POST -H \"Content-Type: application/json\" -d '${adaptive_card_payload}' '${configuration.webhook_url}'" ].execute().text
print process