summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyr Shatskyy <kyrylo.shatskyy@gmail.com>2019-02-26 15:04:54 +0100
committerKyrylo Shatskyy <kyrylo.shatskyy@gmail.com>2019-03-04 20:54:58 +0000
commitb67c0bc754bfa2dd79921f4eb7a47ec1ded6690e (patch)
tree753f60c41d32017c2dced9bfee5fd48e088021c3
parent9f84f69f3c117e5f2bccbcd516363b7c9eeb7b57 (diff)
Add support for 'RocketChat Notifier Plugin'HEADmaster
Change-Id: I78755fb1d116a6e164817589457fe132b81a89eb Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@gmail.com>
Notes
Notes (review): Code-Review+2: Sorin Sbarnea <ssbarnea@redhat.com> Code-Review+2: Thanh Ha (zxiiro) <zxiiro@gmail.com> Workflow+1: Thanh Ha (zxiiro) <zxiiro@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 08 Mar 2019 03:45:21 +0000 Reviewed-on: https://review.openstack.org/639342 Project: openstack-infra/jenkins-job-builder Branch: refs/heads/master
-rw-r--r--jenkins_jobs/modules/publishers.py127
-rw-r--r--tests/publishers/fixtures/rocket001.xml25
-rw-r--r--tests/publishers/fixtures/rocket001.yaml3
-rw-r--r--tests/publishers/fixtures/rocket002.xml56
-rw-r--r--tests/publishers/fixtures/rocket002.yaml42
5 files changed, 253 insertions, 0 deletions
diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py
index 38cf575..c20236b 100644
--- a/jenkins_jobs/modules/publishers.py
+++ b/jenkins_jobs/modules/publishers.py
@@ -1267,6 +1267,133 @@ def ftp_publisher(registry, xml_parent, data):
1267 helpers.convert_mapping_to_xml(ftp, data, mapping, fail_required=True) 1267 helpers.convert_mapping_to_xml(ftp, data, mapping, fail_required=True)
1268 1268
1269 1269
1270def rocket(registry, xml_parent, data):
1271 """yaml: rocket
1272 RocketChat notification on build completion,
1273 Requires the `RocketChat Notifier Plugin`.
1274
1275 :arg str channel: Comma separated list of rooms (e.g. #project)
1276 or persons (e.g. @john)
1277 :arg bool abort: Notify abort (default false)
1278 :arg bool start: Notify start (default false)
1279 :arg bool success: Notify success (default false)
1280 :arg bool failure: Notify failure (default false)
1281 :arg bool repeated-failure: Notify repeated failure (default false)
1282 :arg bool back-to-normal: Notify back to normal (default false)
1283 :arg bool not-built: Notify if not built (default false)
1284 :arg bool unstable: Notify if unstable (default false)
1285 :arg str webhook-token: Webhook token for posting messages.
1286 Overrides global authentication data and channel
1287 :arg str commit-info: What commit information to include into
1288 notification message.
1289
1290 :commit-info values:
1291 * **none**
1292 * **authors**
1293 * **authors-and-titles**
1294
1295 :arg str custom-message: Custom text message (default '')
1296 :arg bool trust-ssl: Trust RocketChat server certificate, if checked,
1297 the SSL certificate will not be checked (default false)
1298 :arg str build-server: Build Server URL
1299 :arg list attachments: Optional list of attachments
1300
1301 :attachments:
1302 * **title** (`str`) Attachment title (required)
1303 * **title-link** (`str`)
1304 * **title-link-download** (`bool`)
1305 * **color** (`str`)
1306 * **text** (`str`)
1307 * **collapsed** (`bool`)
1308 * **message-link** (`str`)
1309 * **author-name** (`str`)
1310 * **author-link** (`str`)
1311 * **author-icon** (`str`)
1312 * **thumb** (`str`) Thumb URL
1313 * **image** (`str`) Image URL
1314 * **audio** (`str`) Audio URL
1315 * **video** (`str`) Video URL
1316
1317 Minimal example using defaults:
1318
1319 .. literalinclude:: /../../tests/publishers/fixtures/rocket001.yaml
1320 :language: yaml
1321
1322 Full example:
1323
1324 .. literalinclude:: /../../tests/publishers/fixtures/rocket002.yaml
1325 :language: yaml
1326 """
1327 rocketchat = XML.SubElement(xml_parent,
1328 'jenkins.plugins.rocketchatnotifier.RocketChatNotifier')
1329 rocketchat.set('plugin', 'rocketchatnotifier')
1330 required_mapping = [
1331 ('channel', 'channel', ''),
1332 ('start', 'startNotification', False),
1333 ('success', 'notifySuccess', False),
1334 ('abort', 'notifyAborted', False),
1335 ('not-built', 'notifyNotBuilt', False),
1336 ('unstable', 'notifyUnstable', False),
1337 ('failure', 'notifyFailure', False),
1338 ('back-to-normal', 'notifyBackToNormal', False),
1339 ('repeated-failure', 'notifyRepeatedFailure', False),
1340 ('include-test-summary', 'includeTestSummary', False),
1341 ('include-test-log', 'includeTestLog', False),
1342 ('include-custom-message', 'includeCustomMessage', False),
1343 ('commit-info', 'commitInfoChoice', 'none',
1344 {
1345 'none': 'NONE',
1346 'authors': 'AUTHORS',
1347 'authors-and-titles': 'AUTHORS_AND_TITLES'
1348 }),
1349 ('raw-message', 'rawMessage', False),
1350 ('webhook-token', 'webhookToken', ''),
1351 ('webhook-token-credential-id', 'webhookTokenCredentialId', ''),
1352 ]
1353 optional_mapping = [
1354 ('trust-ssl', 'trustSSL', None),
1355 ('build-server', 'buildServerUrl', None),
1356 ]
1357
1358 helpers.convert_mapping_to_xml(
1359 rocketchat, data, optional_mapping, fail_required=False)
1360 helpers.convert_mapping_to_xml(
1361 rocketchat, data, required_mapping, fail_required=True)
1362
1363 attach_required_mapping = [
1364 ('title', 'title', None),
1365 ]
1366 attach_optional_mapping = [
1367 ('title-link', 'titleLink', None),
1368 ('title-link-download', 'titleLinkDownload', None),
1369 ('color', 'color', None),
1370 ('text', 'text', None),
1371 ('collapsed', 'collapsed', None), # false | true
1372 ('message-link', 'messageLink', None),
1373 ('author-name', 'authorName', None),
1374 ('author-link', 'authorLink', None),
1375 ('author-icon', 'authorIcon', None),
1376 ('thumb', 'thumbUrl', None),
1377 ('image', 'imageUrl', None),
1378 ('audio', 'audioUrl', None),
1379 ('video', 'videoUrl', None),
1380 ]
1381 attach_list = data.get('attachments', None)
1382
1383 attachments = XML.SubElement(rocketchat, 'attachments')
1384 if attach_list is not None:
1385 for attach_data in attach_list:
1386 item = XML.SubElement(attachments,
1387 'jenkins.plugins.rocketchatnotifier.model.MessageAttachment')
1388 helpers.convert_mapping_to_xml(item, attach_data,
1389 attach_required_mapping, fail_required=True)
1390 helpers.convert_mapping_to_xml(item, attach_data,
1391 attach_optional_mapping, fail_required=False)
1392
1393 XML.SubElement(rocketchat, 'customMessage').text = \
1394 data.get('custom-message', '')
1395
1396
1270def junit(registry, xml_parent, data): 1397def junit(registry, xml_parent, data):
1271 """yaml: junit 1398 """yaml: junit
1272 Publish JUnit test results. 1399 Publish JUnit test results.
diff --git a/tests/publishers/fixtures/rocket001.xml b/tests/publishers/fixtures/rocket001.xml
new file mode 100644
index 0000000..0d95d12
--- /dev/null
+++ b/tests/publishers/fixtures/rocket001.xml
@@ -0,0 +1,25 @@
1<?xml version="1.0" encoding="utf-8"?>
2<project>
3 <publishers>
4 <jenkins.plugins.rocketchatnotifier.RocketChatNotifier plugin="rocketchatnotifier">
5 <channel/>
6 <startNotification>false</startNotification>
7 <notifySuccess>false</notifySuccess>
8 <notifyAborted>false</notifyAborted>
9 <notifyNotBuilt>false</notifyNotBuilt>
10 <notifyUnstable>false</notifyUnstable>
11 <notifyFailure>false</notifyFailure>
12 <notifyBackToNormal>false</notifyBackToNormal>
13 <notifyRepeatedFailure>false</notifyRepeatedFailure>
14 <includeTestSummary>false</includeTestSummary>
15 <includeTestLog>false</includeTestLog>
16 <includeCustomMessage>false</includeCustomMessage>
17 <commitInfoChoice>NONE</commitInfoChoice>
18 <rawMessage>false</rawMessage>
19 <webhookToken/>
20 <webhookTokenCredentialId/>
21 <attachments/>
22 <customMessage/>
23 </jenkins.plugins.rocketchatnotifier.RocketChatNotifier>
24 </publishers>
25</project>
diff --git a/tests/publishers/fixtures/rocket001.yaml b/tests/publishers/fixtures/rocket001.yaml
new file mode 100644
index 0000000..b4e7b51
--- /dev/null
+++ b/tests/publishers/fixtures/rocket001.yaml
@@ -0,0 +1,3 @@
1publishers:
2- rocket:
3 channel: ''
diff --git a/tests/publishers/fixtures/rocket002.xml b/tests/publishers/fixtures/rocket002.xml
new file mode 100644
index 0000000..8d0f364
--- /dev/null
+++ b/tests/publishers/fixtures/rocket002.xml
@@ -0,0 +1,56 @@
1<?xml version="1.0" encoding="utf-8"?>
2<project>
3 <publishers>
4 <jenkins.plugins.rocketchatnotifier.RocketChatNotifier plugin="rocketchatnotifier">
5 <trustSSL>true</trustSSL>
6 <buildServerUrl>http://localhost:8080/</buildServerUrl>
7 <channel>#channel,@user</channel>
8 <startNotification>true</startNotification>
9 <notifySuccess>true</notifySuccess>
10 <notifyAborted>true</notifyAborted>
11 <notifyNotBuilt>true</notifyNotBuilt>
12 <notifyUnstable>true</notifyUnstable>
13 <notifyFailure>true</notifyFailure>
14 <notifyBackToNormal>true</notifyBackToNormal>
15 <notifyRepeatedFailure>true</notifyRepeatedFailure>
16 <includeTestSummary>true</includeTestSummary>
17 <includeTestLog>true</includeTestLog>
18 <includeCustomMessage>true</includeCustomMessage>
19 <commitInfoChoice>AUTHORS_AND_TITLES</commitInfoChoice>
20 <rawMessage>true</rawMessage>
21 <webhookToken>non-secure-webhook-token</webhookToken>
22 <webhookTokenCredentialId>secret-text-id</webhookTokenCredentialId>
23 <attachments>
24 <jenkins.plugins.rocketchatnotifier.model.MessageAttachment>
25 <title>The Black</title>
26 </jenkins.plugins.rocketchatnotifier.model.MessageAttachment>
27 <jenkins.plugins.rocketchatnotifier.model.MessageAttachment>
28 <title>The Red</title>
29 <color>red</color>
30 </jenkins.plugins.rocketchatnotifier.model.MessageAttachment>
31 <jenkins.plugins.rocketchatnotifier.model.MessageAttachment>
32 <title>The Blue</title>
33 <color>blue</color>
34 <text>The navy blue</text>
35 </jenkins.plugins.rocketchatnotifier.model.MessageAttachment>
36 <jenkins.plugins.rocketchatnotifier.model.MessageAttachment>
37 <title>The White</title>
38 <titleLink>title_link</titleLink>
39 <titleLinkDownload>true</titleLinkDownload>
40 <color>white</color>
41 <text>All&amp;all</text>
42 <collapsed>true</collapsed>
43 <messageLink>message_link</messageLink>
44 <authorName>author_name</authorName>
45 <authorLink>author_link</authorLink>
46 <authorIcon>author_icon</authorIcon>
47 <thumbUrl>http://hostname/thumb.png</thumbUrl>
48 <imageUrl>http://hostname/image.jpg</imageUrl>
49 <audioUrl>http://hostname/audio.mp3</audioUrl>
50 <videoUrl>http://hostname/video.avi</videoUrl>
51 </jenkins.plugins.rocketchatnotifier.model.MessageAttachment>
52 </attachments>
53 <customMessage>Hello World!</customMessage>
54 </jenkins.plugins.rocketchatnotifier.RocketChatNotifier>
55 </publishers>
56</project>
diff --git a/tests/publishers/fixtures/rocket002.yaml b/tests/publishers/fixtures/rocket002.yaml
new file mode 100644
index 0000000..d94c25b
--- /dev/null
+++ b/tests/publishers/fixtures/rocket002.yaml
@@ -0,0 +1,42 @@
1publishers:
2- rocket:
3 channel: '#channel,@user'
4 abort: true
5 back-to-normal: true
6 failure: true
7 not-built: true
8 repeated-failure: true
9 start: true
10 success: true
11 unstable: true
12 trust-ssl: true
13 build-server: 'http://localhost:8080/'
14 webhook-token: 'non-secure-webhook-token'
15 webhook-token-credential-id: 'secret-text-id'
16 commit-info: 'authors-and-titles'
17 include-custom-message: true
18 include-test-log: true
19 include-test-summary: true
20 custom-message: 'Hello World!'
21 raw-message: true
22 attachments:
23 - title: The Black
24 - title: The Red
25 color: red
26 - title: The Blue
27 color: blue
28 text: The navy blue
29 - title: The White
30 title-link: title_link
31 title-link-download: true
32 message-link: message_link
33 color: white
34 text: 'All&all'
35 collapsed: true
36 author-name: author_name
37 author-link: author_link
38 author-icon: author_icon
39 thumb: 'http://hostname/thumb.png'
40 image: 'http://hostname/image.jpg'
41 audio: 'http://hostname/audio.mp3'
42 video: 'http://hostname/video.avi'