Adding more configurable options in Notifications plugin

-- Added support for selecting the following options:
    * Format
    * Protocol
    * Timeout
    * Log level

Change-Id: Ib5cf6606b0818167d72319fd29df2b6230f1becf
This commit is contained in:
Somay Jain 2015-03-11 02:57:34 +05:30
parent be8def7829
commit 93322575b0
4 changed files with 63 additions and 13 deletions

View File

@ -22,19 +22,11 @@ Jenkins notification plugin.
:Macro: notification
:Entry Point: jenkins_jobs.notifications
Example::
job:
name: test_job
notifications:
- http:
url: http://example.com/jenkins_endpoint
"""
import xml.etree.ElementTree as XML
import jenkins_jobs.modules.base
from jenkins_jobs.errors import JenkinsJobsException
def http_endpoint(parser, xml_parent, data):
@ -43,19 +35,49 @@ def http_endpoint(parser, xml_parent, data):
Requires the Jenkins :jenkins-wiki:`Notification Plugin
<Notification+Plugin>`.
:arg str format: notification payload format, JSON (default) or XML
:arg str event: job events that trigger notifications: started,
completed, finalized or all (default)
:arg str url: URL of the endpoint
:arg str timeout: Timeout in milliseconds for sending notification
request (30 seconds by default)
:arg str log: Number lines of log messages to send (0 by default).
Use -1 for all (use with caution).
Example::
Example:
.. literalinclude:: \
/../../tests/notifications/fixtures/http-endpoint002.yaml
:language: yaml
notifications:
- http:
url: http://example.com/jenkins_endpoint
"""
endpoint_element = XML.SubElement(xml_parent,
'com.tikal.hudson.plugins.notification.'
'Endpoint')
supported_formats = ['JSON', 'XML']
format = data.get('format', 'JSON').upper()
if format not in supported_formats:
raise JenkinsJobsException(
"format must be one of %s" %
", ".join(supported_formats))
else:
XML.SubElement(endpoint_element, 'format').text = format
XML.SubElement(endpoint_element, 'protocol').text = 'HTTP'
supported_events = ['started', 'completed', 'finalized', 'all']
event = data.get('event', 'all').lower()
if event not in supported_events:
raise JenkinsJobsException(
"event must be one of %s" %
", ".join(supported_events))
else:
XML.SubElement(endpoint_element, 'event').text = event
XML.SubElement(endpoint_element, 'timeout').text = str(data.get('timeout',
30000))
XML.SubElement(endpoint_element, 'url').text = data['url']
XML.SubElement(endpoint_element, 'loglines').text = str(data.get('log', 0))
class Notifications(jenkins_jobs.modules.base.Base):

View File

@ -4,8 +4,12 @@
<com.tikal.hudson.plugins.notification.HudsonNotificationProperty>
<endpoints>
<com.tikal.hudson.plugins.notification.Endpoint>
<format>JSON</format>
<protocol>HTTP</protocol>
<event>all</event>
<timeout>30000</timeout>
<url>http://example.com/jenkins_endpoint</url>
<loglines>0</loglines>
</com.tikal.hudson.plugins.notification.Endpoint>
</endpoints>
</com.tikal.hudson.plugins.notification.HudsonNotificationProperty>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<com.tikal.hudson.plugins.notification.HudsonNotificationProperty>
<endpoints>
<com.tikal.hudson.plugins.notification.Endpoint>
<format>XML</format>
<protocol>HTTP</protocol>
<event>completed</event>
<timeout>40000</timeout>
<url>http://example.com/jenkins_endpoint</url>
<loglines>-1</loglines>
</com.tikal.hudson.plugins.notification.Endpoint>
</endpoints>
</com.tikal.hudson.plugins.notification.HudsonNotificationProperty>
</properties>
</project>

View File

@ -0,0 +1,7 @@
notifications:
- http:
url: http://example.com/jenkins_endpoint
format: xml
event: completed
timeout: 40000
log: -1