This repository has been archived by the owner on Feb 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemail.groovy
161 lines (150 loc) · 4.11 KB
/
email.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import com.concur.*;
workflowDoc = '''
title: Email
overview: Send an email within your pipeline.
additional_resources:
- name: Mail plugin site
url: https://plugins.jenkins.io/workflow-basic-steps
tools:
- type: String
name: to
required: true
description: The address to send this email to.
- type: String
name: subject
required: true
description: The subject of the email.
- type: String
name: body
required: true
description: The body of the email to send.
- type: String
name: from
description: Who to show the email was sent from.
- type: String
name: bcc
description: BCC email address list.
- type: String
name: cc
description: CC email address list.
- type: String
name: charset
description: Email body character encoding.
default: UTF-8
- type: String
name: mimeType
description: Email body MIME type.
default: text/plain.
- type: String
name: replyTo
description: Reply-To email address.
full_example: |
pipelines:
tools:
email:
replyTo: [email protected]
branches:
patterns:
feature: .+
branches:
feature:
steps:
- custom: # This should be your build process
- buildPackage:
- email:
- send:
body: "Deployment to staging successful for branch {{ branch_name }} | {{ build_url }}"
master:
steps:
- email:
- send:
body: "Merge to master successful, deployment successful | {{ build_url }}"
'''
concurPipeline = new Commands()
concurUtil = new Util()
/*
description: Send an email.
parameters:
- type: String
name: to
required: true
description: The address to send this email to.
- type: String
name: subject
required: true
description: The subject of the email.
- type: String
name: body
required: true
description: The body of the email to send.
- type: String
name: from
description: Who to show the email was sent from.
- type: String
name: bcc
description: BCC email address list.
- type: String
name: cc
description: CC email address list.
- type: String
name: charset
description: Email body character encoding.
default: UTF-8
- type: String
name: mimeType
description: Email body MIME type.
default: text/plain.
- type: String
name: replyTo
description: Reply-To email address.
example: |
branches:
feature:
steps:
- email:
# Simple
- send: "Example email from {{ build_url }}"
# Advanced
- send:
body: "Example email from {{ build_url }}"
*/
public send(Map yml, Map options) {
def emailData = yml.tools?.email ?: [:]
switch (options) {
case Map:
emailData = emailData.plus(options)
break
case String:
emailData.put('body', options)
break
default:
error("Workflows :: email :: send :: The format provided for email options is not supported.")
break
}
assert emailData.to : "Workflows :: email :: send :: No email recipient provided."
assert (emailData.subject || emailData.body) : "Workflows :: email :: send :: No email subject or body provided."
if (!emailData.from) {emailData.put('from', '[email protected]')}
concurPipeline.debugPrint('Workflows :: email :: send', emailData)
emailData.body = emailData.body ? concurUtil.mustacheReplaceAll(emailData.body) : '.'
emailData.subject = emailData.subject ? concurUtil.mustacheReplaceAll(emailData.subject) : 'No Subject'
mail(emailData)
}
/*
* Set the name of the stage dynamically.
*/
public getStageName(Map yml, Map args, String stepName) {
switch(stepName) {
case 'send':
def emailTo = args?.to ?: yml.tools?.email?.to
return emailTo ? "email: send: ${emailTo}" : 'email: send'
}
}
public tests(Map yml, Map args) {
String workflowName = 'email'
println "Testing $workflowName"
}
return this;