Add email publisher/reporter.
Also, add reporters module. Change-Id: I9cd0abca3d90f1af5f275698ecc9ccb7d9086494 Reviewed-on: https://review.openstack.org/13303 Reviewed-by: Monty Taylor <mordred@inaugust.com> Reviewed-by: Clark Boylan <clark.boylan@gmail.com> Approved: James E. Blair <corvus@inaugust.com> Tested-by: Jenkins
This commit is contained in:
parent
db35627b52
commit
a7d33f1b0d
@ -188,6 +188,7 @@ The bulk of the job definitions come from the following modules.
|
||||
parameters
|
||||
properties
|
||||
publishers
|
||||
reporters
|
||||
scm
|
||||
triggers
|
||||
wrappers
|
||||
|
7
doc/source/reporters.rst
Normal file
7
doc/source/reporters.rst
Normal file
@ -0,0 +1,7 @@
|
||||
.. _reporters:
|
||||
|
||||
Reporters
|
||||
=========
|
||||
|
||||
.. automodule:: reporters
|
||||
:members:
|
@ -400,6 +400,37 @@ def pipeline(parser, xml_parent, data):
|
||||
XML.SubElement(pippub, 'downstreamProjectNames').text = data
|
||||
|
||||
|
||||
def email(parser, xml_parent, data):
|
||||
"""yaml: email
|
||||
Email notifications on build failure.
|
||||
|
||||
:arg str recipients: Recipient email addresses
|
||||
:arg bool notify-every-unstable-build: Send an email for every
|
||||
unstable build (default true)
|
||||
:arg bool send-to-individuals: Send an email to the individual
|
||||
who broke the build (default false)
|
||||
|
||||
Example::
|
||||
|
||||
publishers:
|
||||
- email:
|
||||
recipients: breakage@example.com
|
||||
"""
|
||||
|
||||
# TODO: raise exception if this is applied to a maven job
|
||||
mailer = XML.SubElement(xml_parent,
|
||||
'hudson.tasks.Mailer')
|
||||
XML.SubElement(mailer, 'recipients').text = data['recipients']
|
||||
|
||||
# Note the logic reversal (included here to match the GUI
|
||||
if data.get('notify-every-unstable-build', True):
|
||||
XML.SubElement(mailer, 'dontNotifyEveryUnstableBuild').text = 'false'
|
||||
else:
|
||||
XML.SubElement(mailer, 'dontNotifyEveryUnstableBuild').text = 'true'
|
||||
XML.SubElement(mailer, 'sendToIndividuals').text = str(
|
||||
data.get('send-to-individuals', False)).lower()
|
||||
|
||||
|
||||
class Publishers(jenkins_jobs.modules.base.Base):
|
||||
sequence = 70
|
||||
|
||||
|
85
jenkins_jobs/modules/reporters.py
Normal file
85
jenkins_jobs/modules/reporters.py
Normal file
@ -0,0 +1,85 @@
|
||||
# Copyright 2012 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
"""
|
||||
Reporters are like publishers but only applicable to Maven projets.
|
||||
|
||||
**Component**: reporters
|
||||
:Macro: reporter
|
||||
:Entry Point: jenkins_jobs.reporters
|
||||
|
||||
Example::
|
||||
|
||||
job:
|
||||
name: test_job
|
||||
project-type: maven
|
||||
|
||||
reporters:
|
||||
- email:
|
||||
recipients: breakage@example.com
|
||||
"""
|
||||
|
||||
|
||||
import xml.etree.ElementTree as XML
|
||||
import jenkins_jobs.modules.base
|
||||
|
||||
|
||||
def email(parser, xml_parent, data):
|
||||
"""yaml: email
|
||||
Email notifications on build failure.
|
||||
|
||||
:arg str recipients: Recipient email addresses
|
||||
:arg bool notify-every-unstable-build: Send an email for every
|
||||
unstable build (default true)
|
||||
:arg bool send-to-individuals: Send an email to the individual
|
||||
who broke the build (default false)
|
||||
|
||||
Example::
|
||||
|
||||
reporters:
|
||||
- email:
|
||||
recipients: breakage@example.com
|
||||
"""
|
||||
|
||||
mailer = XML.SubElement(xml_parent,
|
||||
'hudson.maven.reporters.Mailer')
|
||||
XML.SubElement(mailer, 'recipients').text = data['recipients']
|
||||
|
||||
# Note the logic reversal (included here to match the GUI
|
||||
if data.get('notify-every-unstable-build', True):
|
||||
XML.SubElement(mailer, 'dontNotifyEveryUnstableBuild').text = 'false'
|
||||
else:
|
||||
XML.SubElement(mailer, 'dontNotifyEveryUnstableBuild').text = 'true'
|
||||
XML.SubElement(mailer, 'sendToIndividuals').text = str(
|
||||
data.get('send-to-individuals', False)).lower()
|
||||
# TODO: figure out what this is:
|
||||
XML.SubElement(mailer, 'perModuleEmail').text = 'true'
|
||||
|
||||
|
||||
class Reporters(jenkins_jobs.modules.base.Base):
|
||||
sequence = 55
|
||||
|
||||
def gen_xml(self, parser, xml_parent, data):
|
||||
if 'reporters' not in data:
|
||||
return
|
||||
|
||||
if xml_parent.tag != 'maven2-moduleset':
|
||||
raise Exception("Reporters may only be used for Maven modules.")
|
||||
|
||||
reporters = XML.SubElement(xml_parent, 'reporters')
|
||||
|
||||
for action in data.get('reporters', []):
|
||||
self._dispatch('reporter', 'reporters',
|
||||
parser, reporters, action)
|
5
setup.py
5
setup.py
@ -36,6 +36,9 @@ setup(name='jenkins_job_builder',
|
||||
'trigger-builds=jenkins_jobs.modules.builders:trigger_builds',
|
||||
'builders-from=jenkins_jobs.modules.builders:builders_from',
|
||||
],
|
||||
'jenkins_jobs.reporters': [
|
||||
'email=jenkins_jobs.modules.reporters:email',
|
||||
],
|
||||
'jenkins_jobs.properties': [
|
||||
'github=jenkins_jobs.modules.properties:github',
|
||||
'throttle=jenkins_jobs.modules.properties:throttle',
|
||||
@ -63,6 +66,7 @@ setup(name='jenkins_job_builder',
|
||||
'violations=jenkins_jobs.modules.publishers:violations',
|
||||
'scp=jenkins_jobs.modules.publishers:scp',
|
||||
'pipeline=jenkins_jobs.modules.publishers:pipeline',
|
||||
'email=jenkins_jobs.modules.publishers:email',
|
||||
],
|
||||
'jenkins_jobs.scm': [
|
||||
'git=jenkins_jobs.modules.scm:git',
|
||||
@ -85,6 +89,7 @@ setup(name='jenkins_job_builder',
|
||||
'parameters=jenkins_jobs.modules.parameters:Parameters',
|
||||
'notifications=jenkins_jobs.modules.notifications:Notifications',
|
||||
'publishers=jenkins_jobs.modules.publishers:Publishers',
|
||||
'reporters=jenkins_jobs.modules.reporters:Reporters',
|
||||
'scm=jenkins_jobs.modules.scm:SCM',
|
||||
'triggers=jenkins_jobs.modules.triggers:Triggers',
|
||||
'wrappers=jenkins_jobs.modules.wrappers:Wrappers',
|
||||
|
Loading…
Reference in New Issue
Block a user