diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 06ca5c00d..c16d1c919 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -1382,6 +1382,9 @@ def email_ext(parser, xml_parent, data): :arg str recipients: Comma separated list of emails :arg str reply-to: Comma separated list of emails that should be in the Reply-To header for this project (default is $DEFAULT_RECIPIENTS) + :arg str content-type: The content type of the emails sent. If not set, the + Jenkins plugin uses the value set on the main configuration page. + Possible values: 'html', 'text' or 'default' (default 'default') :arg str subject: Subject for the email, can include variables like ${BUILD_NUMBER} or even groovy or javascript code :arg str body: Content for the body of the email, can include variables @@ -1447,7 +1450,18 @@ def email_ext(parser, xml_parent, data): base_email_ext(parser, ctrigger, data, 'StillUnstableTrigger') if data.get('pre-build', False): base_email_ext(parser, ctrigger, data, 'PreBuildTrigger') - XML.SubElement(emailext, 'contentType').text = 'default' + + content_type_mime = { + 'text': 'text/plain', + 'html': 'text/html', + 'default': 'default', + } + ctype = data.get('content-type', 'default') + if ctype not in content_type_mime: + raise JenkinsJobsException('email-ext content type must be one of: %s' + % ', '.join(content_type_mime.keys())) + XML.SubElement(emailext, 'contentType').text = content_type_mime[ctype] + XML.SubElement(emailext, 'defaultSubject').text = data.get( 'subject', '$DEFAULT_SUBJECT') XML.SubElement(emailext, 'defaultContent').text = data.get( diff --git a/tests/publishers/fixtures/email-ext001.xml b/tests/publishers/fixtures/email-ext001.xml index 2af3c6980..33d42121c 100644 --- a/tests/publishers/fixtures/email-ext001.xml +++ b/tests/publishers/fixtures/email-ext001.xml @@ -137,7 +137,7 @@ - default + text/html Subject for Build ${BUILD_NUMBER} The build has finished */foo*.log diff --git a/tests/publishers/fixtures/email-ext001.yaml b/tests/publishers/fixtures/email-ext001.yaml index 9459f807c..78ef49059 100644 --- a/tests/publishers/fixtures/email-ext001.yaml +++ b/tests/publishers/fixtures/email-ext001.yaml @@ -2,6 +2,7 @@ publishers: - email-ext: recipients: foo@example.com, bar@example.com reply-to: foo@example.com + content-type: html subject: Subject for Build ${BUILD_NUMBER} body: The build has finished attach-build-log: false