From 09aa1cd1299889830beebb5e95435fc0eb323086 Mon Sep 17 00:00:00 2001 From: Kien Ha Date: Wed, 4 May 2016 22:03:00 -0400 Subject: [PATCH] Add test and update documentation for mailer plugin Add a test for notify-every-unstable-build option because it was missing. Improve the documentation and add recipients as a requirement to the plugin. Change-Id: I1d687e155536da264305dc88e9aac330760d63a5 Signed-off-by: Kien Ha --- jenkins_jobs/modules/publishers.py | 16 +++++++++++++--- .../{email002.xml => email-complete.xml} | 4 ++-- .../{email001.yaml => email-complete.yaml} | 2 ++ .../fixtures/{email001.xml => email-minimal.xml} | 2 +- tests/publishers/fixtures/email-minimal.yaml | 3 +++ tests/publishers/fixtures/email002.yaml | 4 ---- 6 files changed, 21 insertions(+), 10 deletions(-) rename tests/publishers/fixtures/{email002.xml => email-complete.xml} (58%) rename tests/publishers/fixtures/{email001.yaml => email-complete.yaml} (50%) rename tests/publishers/fixtures/{email001.xml => email-minimal.xml} (80%) create mode 100644 tests/publishers/fixtures/email-minimal.yaml delete mode 100644 tests/publishers/fixtures/email002.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index c1b721dad..9d99345b7 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -1724,9 +1724,12 @@ def pipeline(parser, xml_parent, data): def email(parser, xml_parent, data): """yaml: email Email notifications on build failure. + Requires the Jenkins :jenkins-wiki:`Mailer Plugin + `. + :arg str recipients: Space separated list of recipient email addresses - (optional) + (required) :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 @@ -1734,14 +1737,21 @@ def email(parser, xml_parent, data): Example: - .. literalinclude:: /../../tests/publishers/fixtures/email001.yaml + .. literalinclude:: + /../../tests/publishers/fixtures/email-minimal.yaml + :language: yaml + + .. literalinclude:: /../../tests/publishers/fixtures/email-complete.yaml :language: yaml """ # 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.get('recipients', '') + try: + XML.SubElement(mailer, 'recipients').text = data['recipients'] + except KeyError as e: + raise MissingAttributeError(e) # Note the logic reversal (included here to match the GUI if data.get('notify-every-unstable-build', True): diff --git a/tests/publishers/fixtures/email002.xml b/tests/publishers/fixtures/email-complete.xml similarity index 58% rename from tests/publishers/fixtures/email002.xml rename to tests/publishers/fixtures/email-complete.xml index e36117f79..7c7447af9 100644 --- a/tests/publishers/fixtures/email002.xml +++ b/tests/publishers/fixtures/email-complete.xml @@ -2,8 +2,8 @@ - - false + foo@example.com bar@example.com + true true diff --git a/tests/publishers/fixtures/email001.yaml b/tests/publishers/fixtures/email-complete.yaml similarity index 50% rename from tests/publishers/fixtures/email001.yaml rename to tests/publishers/fixtures/email-complete.yaml index e2bb3a3b7..d27397759 100644 --- a/tests/publishers/fixtures/email001.yaml +++ b/tests/publishers/fixtures/email-complete.yaml @@ -1,3 +1,5 @@ publishers: - email: recipients: foo@example.com bar@example.com + notify-every-unstable-build: false + send-to-individuals: true diff --git a/tests/publishers/fixtures/email001.xml b/tests/publishers/fixtures/email-minimal.xml similarity index 80% rename from tests/publishers/fixtures/email001.xml rename to tests/publishers/fixtures/email-minimal.xml index e0a0628c1..aedd0c77f 100644 --- a/tests/publishers/fixtures/email001.xml +++ b/tests/publishers/fixtures/email-minimal.xml @@ -2,7 +2,7 @@ - foo@example.com bar@example.com + foo@example.com false false diff --git a/tests/publishers/fixtures/email-minimal.yaml b/tests/publishers/fixtures/email-minimal.yaml new file mode 100644 index 000000000..d50023897 --- /dev/null +++ b/tests/publishers/fixtures/email-minimal.yaml @@ -0,0 +1,3 @@ +publishers: + - email: + recipients: foo@example.com diff --git a/tests/publishers/fixtures/email002.yaml b/tests/publishers/fixtures/email002.yaml deleted file mode 100644 index c8a8b3ea0..000000000 --- a/tests/publishers/fixtures/email002.yaml +++ /dev/null @@ -1,4 +0,0 @@ -publishers: - - email: - send-to-individuals: true -