From 2f9f589fe5df6626a0f53e72d044d69db8276144 Mon Sep 17 00:00:00 2001 From: K Jonathan Harker Date: Thu, 5 Feb 2015 16:32:57 -0800 Subject: [PATCH] The email publisher needs a list of recipients The email publisher will throw a NullPointerException of the recipients xml element does not exist, so if there are no recipients then set the value to an empty string in order to get an empty xml element in the config. Also add tests for the email publisher. story: 2000015 Change-Id: I7b4fdd4904eea1918ae80f5db6c7b0aaedbaef99 --- jenkins_jobs/modules/publishers.py | 10 ++++------ tests/publishers/fixtures/email001.xml | 10 ++++++++++ tests/publishers/fixtures/email001.yaml | 3 +++ tests/publishers/fixtures/email002.xml | 10 ++++++++++ tests/publishers/fixtures/email002.yaml | 4 ++++ 5 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 tests/publishers/fixtures/email001.xml create mode 100644 tests/publishers/fixtures/email001.yaml create mode 100644 tests/publishers/fixtures/email002.xml create mode 100644 tests/publishers/fixtures/email002.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 880ce4e76..fae33d9b1 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -1298,18 +1298,16 @@ def email(parser, xml_parent, data): :arg bool send-to-individuals: Send an email to the individual who broke the build (default false) - Example:: + Example: - publishers: - - email: - recipients: breakage@example.com + .. literalinclude:: /../../tests/publishers/fixtures/email001.yaml + :language: yaml """ # TODO: raise exception if this is applied to a maven job mailer = XML.SubElement(xml_parent, 'hudson.tasks.Mailer') - if 'recipients' in data: - XML.SubElement(mailer, 'recipients').text = data['recipients'] + XML.SubElement(mailer, 'recipients').text = data.get('recipients', '') # Note the logic reversal (included here to match the GUI if data.get('notify-every-unstable-build', True): diff --git a/tests/publishers/fixtures/email001.xml b/tests/publishers/fixtures/email001.xml new file mode 100644 index 000000000..e0a0628c1 --- /dev/null +++ b/tests/publishers/fixtures/email001.xml @@ -0,0 +1,10 @@ + + + + + foo@example.com bar@example.com + false + false + + + diff --git a/tests/publishers/fixtures/email001.yaml b/tests/publishers/fixtures/email001.yaml new file mode 100644 index 000000000..e2bb3a3b7 --- /dev/null +++ b/tests/publishers/fixtures/email001.yaml @@ -0,0 +1,3 @@ +publishers: + - email: + recipients: foo@example.com bar@example.com diff --git a/tests/publishers/fixtures/email002.xml b/tests/publishers/fixtures/email002.xml new file mode 100644 index 000000000..e36117f79 --- /dev/null +++ b/tests/publishers/fixtures/email002.xml @@ -0,0 +1,10 @@ + + + + + + false + true + + + diff --git a/tests/publishers/fixtures/email002.yaml b/tests/publishers/fixtures/email002.yaml new file mode 100644 index 000000000..c8a8b3ea0 --- /dev/null +++ b/tests/publishers/fixtures/email002.yaml @@ -0,0 +1,4 @@ +publishers: + - email: + send-to-individuals: true +