diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index d3174ed92..90e968fd4 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -4784,6 +4784,84 @@ def google_cloud_storage(parser, xml_parent, data): properties, upload_element, types) +def flowdock(parser, xml_parent, data): + """yaml: flowdock + This plugin publishes job build results to a Flowdock flow. + + Requires the Jenkins :jenkins-wiki:`Flowdock Plugin + `. + + :arg str token: API token for the targeted flow. + (required) + :arg str tags: Comma-separated list of tags to incude in message + (default "") + :arg bool chat-notification: Send chat notification when build fails + (default true) + :arg bool notify-success: Send notification on build success + (default true) + :arg bool notify-failure: Send notification on build failure + (default true) + :arg bool notify-fixed: Send notification when build is fixed + (default true) + :arg bool notify-unstable: Send notification when build is unstable + (default false) + :arg bool notify-aborted: Send notification when build was aborted + (default false) + :arg bool notify-notbuilt: Send notification when build did not occur + (default false) + + Example: + + .. literalinclude:: /../../tests/publishers/fixtures/flowdock001.yaml + :language: yaml + + Full example: + + .. literalinclude:: /../../tests/publishers/fixtures/flowdock002.yaml + :language: yaml + """ + + def gen_notification_entry(data_item, default, text): + e = XML.SubElement(nm, 'entry') + XML.SubElement(e, 'com.flowdock.jenkins.BuildResult').text = text + XML.SubElement(e, 'boolean').text = str( + data.get(data_item, default)).lower() + + def gen_setting(item, default): + XML.SubElement(parent, 'notify%s' % item).text = str( + data.get('notify-%s' % item.lower(), default)).lower() + + # Raise exception if token was not specified + if 'token' not in data: + raise MissingAttributeError('token') + + parent = XML.SubElement(xml_parent, + 'com.flowdock.jenkins.FlowdockNotifier') + + XML.SubElement(parent, 'flowToken').text = data['token'] + XML.SubElement(parent, 'notificationTags').text = data.get('tags', '') + XML.SubElement(parent, 'chatNotification').text = str( + data.get('chat-notification', True)).lower() + + nm = XML.SubElement(parent, 'notifyMap') + + # notification entries + gen_notification_entry('notify-success', True, 'SUCCESS') + gen_notification_entry('notify-failure', True, 'FAILURE') + gen_notification_entry('notify-fixed', True, 'FIXED') + gen_notification_entry('notify-unstable', False, 'UNSTABLE') + gen_notification_entry('notify-aborted', False, 'ABORTED') + gen_notification_entry('notify-notbuilt', False, 'NOT_BUILT') + + # notification settings + gen_setting('Success', True) + gen_setting('Failure', True) + gen_setting('Fixed', True) + gen_setting('Unstable', False) + gen_setting('Aborted', False) + gen_setting('NotBuilt', False) + + class Publishers(jenkins_jobs.modules.base.Base): sequence = 70 diff --git a/setup.cfg b/setup.cfg index 7ddece1c1..37ec916fc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -161,6 +161,7 @@ jenkins_jobs.publishers = findbugs=jenkins_jobs.modules.publishers:findbugs fingerprint=jenkins_jobs.modules.publishers:fingerprint fitnesse=jenkins_jobs.modules.publishers:fitnesse + flowdock=jenkins_jobs.modules.publishers:flowdock ftp=jenkins_jobs.modules.publishers:ftp gatling=jenkins_jobs.modules.publishers:gatling git=jenkins_jobs.modules.publishers:git diff --git a/tests/publishers/fixtures/flowdock001.xml b/tests/publishers/fixtures/flowdock001.xml new file mode 100644 index 000000000..15642fad4 --- /dev/null +++ b/tests/publishers/fixtures/flowdock001.xml @@ -0,0 +1,42 @@ + + + + + abcdefghijklmnopqrstuvwxyzabcdef + + true + + + SUCCESS + true + + + FAILURE + true + + + FIXED + true + + + UNSTABLE + false + + + ABORTED + false + + + NOT_BUILT + false + + + true + true + true + false + false + false + + + diff --git a/tests/publishers/fixtures/flowdock001.yaml b/tests/publishers/fixtures/flowdock001.yaml new file mode 100644 index 000000000..9bd978e34 --- /dev/null +++ b/tests/publishers/fixtures/flowdock001.yaml @@ -0,0 +1,3 @@ +publishers: + - flowdock: + token: abcdefghijklmnopqrstuvwxyzabcdef diff --git a/tests/publishers/fixtures/flowdock002.xml b/tests/publishers/fixtures/flowdock002.xml new file mode 100644 index 000000000..5cfba6da5 --- /dev/null +++ b/tests/publishers/fixtures/flowdock002.xml @@ -0,0 +1,42 @@ + + + + + abcdefghijklmnopqrstuvwxyzabcdef + jenkins,ci + true + + + SUCCESS + true + + + FAILURE + true + + + FIXED + true + + + UNSTABLE + false + + + ABORTED + false + + + NOT_BUILT + false + + + true + true + true + false + false + false + + + diff --git a/tests/publishers/fixtures/flowdock002.yaml b/tests/publishers/fixtures/flowdock002.yaml new file mode 100644 index 000000000..a524b37f7 --- /dev/null +++ b/tests/publishers/fixtures/flowdock002.yaml @@ -0,0 +1,11 @@ +publishers: + - flowdock: + token: abcdefghijklmnopqrstuvwxyzabcdef + tags: jenkins,ci + chat-notification: true + notify-success: true + notify-failure: true + notify-fixed: true + notify-unstable: false + notify-aborted: false + notify-notbuilt: false diff --git a/tests/publishers/fixtures/flowdock003.xml b/tests/publishers/fixtures/flowdock003.xml new file mode 100644 index 000000000..700a78e57 --- /dev/null +++ b/tests/publishers/fixtures/flowdock003.xml @@ -0,0 +1,42 @@ + + + + + abcdefghijklmnopqrstuvwxyzabcdef + jenkins,ci + false + + + SUCCESS + false + + + FAILURE + false + + + FIXED + false + + + UNSTABLE + true + + + ABORTED + true + + + NOT_BUILT + true + + + false + false + false + true + true + true + + + diff --git a/tests/publishers/fixtures/flowdock003.yaml b/tests/publishers/fixtures/flowdock003.yaml new file mode 100644 index 000000000..6dac1ad28 --- /dev/null +++ b/tests/publishers/fixtures/flowdock003.yaml @@ -0,0 +1,11 @@ +publishers: + - flowdock: + token: abcdefghijklmnopqrstuvwxyzabcdef + tags: jenkins,ci + chat-notification: false + notify-success: false + notify-failure: false + notify-fixed: false + notify-unstable: true + notify-aborted: true + notify-notbuilt: true