From b61cd60024fc2910af6b9400a9caadb6b31464ca Mon Sep 17 00:00:00 2001 From: David Smith Date: Fri, 26 Aug 2016 17:00:00 +0100 Subject: [PATCH] email-ext trigger script You can use Trigger Scripts in groovy to define before of after the build if the email must be send or not. See https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin#Email-extplugin-Triggers Change-Id: Id55df2c4796472c9283269e9e57815b8cf5ed52a --- jenkins_jobs/modules/publishers.py | 6 + tests/publishers/fixtures/email-ext003.xml | 188 ++++++++++++++++++++ tests/publishers/fixtures/email-ext003.yaml | 34 ++++ 3 files changed, 228 insertions(+) create mode 100644 tests/publishers/fixtures/email-ext003.xml create mode 100644 tests/publishers/fixtures/email-ext003.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index c324197db..7e8021a5d 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -1864,6 +1864,8 @@ def base_email_ext(registry, xml_parent, data, ttype): XML.SubElement(email, 'sendToDevelopers').text = 'false' XML.SubElement(email, 'includeCulprits').text = 'false' XML.SubElement(email, 'sendToRecipientList').text = 'true' + if ttype == 'ScriptTrigger': + XML.SubElement(trigger, 'triggerScript').text = data['trigger-script'] def email_ext(registry, xml_parent, data): @@ -1911,6 +1913,8 @@ def email_ext(registry, xml_parent, data): :arg bool still-unstable: Send an email if the build is still unstable (default false) :arg bool pre-build: Send an email before the build (default false) + :arg str trigger-script: A Groovy script used to determine if an email + should be sent. :arg str presend-script: A Groovy script executed prior sending the mail. (default '') :arg str postsend-script: A Goovy script executed after sending the email. @@ -1971,6 +1975,8 @@ def email_ext(registry, xml_parent, data): base_email_ext(registry, ctrigger, data, 'StillUnstableTrigger') if data.get('pre-build', False): base_email_ext(registry, ctrigger, data, 'PreBuildTrigger') + if data.get('trigger-script', False): + base_email_ext(registry, ctrigger, data, 'ScriptTrigger') content_type_mime = { 'text': 'text/plain', diff --git a/tests/publishers/fixtures/email-ext003.xml b/tests/publishers/fixtures/email-ext003.xml new file mode 100644 index 000000000..880ce7fc4 --- /dev/null +++ b/tests/publishers/fixtures/email-ext003.xml @@ -0,0 +1,188 @@ + + + + + foo@example.com, bar@example.com + + + + + $PROJECT_DEFAULT_SUBJECT + $PROJECT_DEFAULT_CONTENT + true + true + true + true + + + + + + $PROJECT_DEFAULT_SUBJECT + $PROJECT_DEFAULT_CONTENT + true + true + true + true + + + + + + $PROJECT_DEFAULT_SUBJECT + $PROJECT_DEFAULT_CONTENT + true + true + true + true + + + + + + $PROJECT_DEFAULT_SUBJECT + $PROJECT_DEFAULT_CONTENT + true + true + true + true + + + + + + $PROJECT_DEFAULT_SUBJECT + $PROJECT_DEFAULT_CONTENT + true + true + true + true + + + + + + $PROJECT_DEFAULT_SUBJECT + $PROJECT_DEFAULT_CONTENT + true + true + true + true + + + + + + $PROJECT_DEFAULT_SUBJECT + $PROJECT_DEFAULT_CONTENT + true + true + true + true + + + + + + $PROJECT_DEFAULT_SUBJECT + $PROJECT_DEFAULT_CONTENT + true + true + true + true + + + + + + $PROJECT_DEFAULT_SUBJECT + $PROJECT_DEFAULT_CONTENT + true + true + true + true + + + + + + $PROJECT_DEFAULT_SUBJECT + $PROJECT_DEFAULT_CONTENT + true + true + true + true + + + + + + $PROJECT_DEFAULT_SUBJECT + $PROJECT_DEFAULT_CONTENT + true + true + true + true + + + + + + $PROJECT_DEFAULT_SUBJECT + $PROJECT_DEFAULT_CONTENT + true + true + true + true + + + + + + $PROJECT_DEFAULT_SUBJECT + $PROJECT_DEFAULT_CONTENT + true + true + true + true + + + + + + $PROJECT_DEFAULT_SUBJECT + $PROJECT_DEFAULT_CONTENT + true + true + true + true + + + + + + $PROJECT_DEFAULT_SUBJECT + $PROJECT_DEFAULT_CONTENT + true + true + true + true + + build.result.toString().equals('SUCCESS') + + + text/html + Subject for Build ${BUILD_NUMBER} + The build has finished + */foo*.log + cancel=true + cancel=true + false + false + true + false + foo@example.com + ONLY_CONFIGURATIONS + + + diff --git a/tests/publishers/fixtures/email-ext003.yaml b/tests/publishers/fixtures/email-ext003.yaml new file mode 100644 index 000000000..0ad5c2941 --- /dev/null +++ b/tests/publishers/fixtures/email-ext003.yaml @@ -0,0 +1,34 @@ +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 + compress-log: false + attachments: "*/foo*.log" + always: true + unstable: true + first-failure: true + not-built: true + aborted: true + regression: true + failure: true + second-failure: true + improvement: true + still-failing: true + success: true + fixed: true + still-unstable: true + pre-build: true + trigger-script: "build.result.toString().equals('SUCCESS')" + matrix-trigger: only-configurations + presend-script: "cancel=true" + postsend-script: "cancel=true" + save-output: true + send-to: + - developers + - requester + - culprits + - recipients