From 30e78cbc7c73b8c3b1bad09a56738fea107f0c35 Mon Sep 17 00:00:00 2001 From: Kei YAMAZAKI Date: Thu, 18 Sep 2014 20:59:59 +0900 Subject: [PATCH] Add support for Jenkins Sounds plugin Change-Id: Ib5b8d24549ef47c308a49ed79d9cb1784cb67921 --- jenkins_jobs/modules/publishers.py | 82 ++++++++++++++++++++++++ tests/publishers/fixtures/sounds001.xml | 50 +++++++++++++++ tests/publishers/fixtures/sounds001.yaml | 4 ++ tests/publishers/fixtures/sounds002.xml | 50 +++++++++++++++ tests/publishers/fixtures/sounds002.yaml | 10 +++ tests/publishers/fixtures/sounds003.xml | 61 ++++++++++++++++++ tests/publishers/fixtures/sounds003.yaml | 13 ++++ 7 files changed, 270 insertions(+) create mode 100644 tests/publishers/fixtures/sounds001.xml create mode 100644 tests/publishers/fixtures/sounds001.yaml create mode 100644 tests/publishers/fixtures/sounds002.xml create mode 100644 tests/publishers/fixtures/sounds002.yaml create mode 100644 tests/publishers/fixtures/sounds003.xml create mode 100644 tests/publishers/fixtures/sounds003.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 29dab8bf2..a2a5fe6df 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -2867,6 +2867,88 @@ def sonar(registry, xml_parent, data): helpers.config_file_provider_settings(sonar, data) +def sounds(parser, xml_parent, data): + """yaml: sounds + Play audio clips locally through sound hardware, + remotely by piping them through an operating system command, + or simultaneously through all browsers on a Jenkins page. + + Requires the Jenkins :jenkins-wiki:`Jenkins Sounds plugin + ` + + :arg dict success: Play on success + + :success: + .. _sound_and_cond: + + * **sound** (`str`) - Sound name + * **from** (`list`) - Previous build result (default is all) + :from values: + * **success** + * **unstable** + * **failure** + * **not_build** + * **aborted** + + :arg dict unstable: Play on unstable. + Specifying sound and conditions see :ref:`above `. + :arg dict failure: Play on failure. + Specifying sound and conditions see :ref:`above `. + :arg dict not_build: Play on not build. + Specifying sound and conditions see :ref:`above `. + :arg dict aborted: Play on aborted. + Specifying sound and conditions see :ref:`above `. + + Minimal example using defaults: + + .. literalinclude:: /../../tests/publishers/fixtures/sounds001.yaml + :language: yaml + + Full example: + + .. literalinclude:: /../../tests/publishers/fixtures/sounds003.yaml + :language: yaml + """ + + mapping_dict = {'success': hudson_model.SUCCESS, + 'unstable': hudson_model.UNSTABLE, + 'failure': hudson_model.FAILURE, + 'not_build': hudson_model.NOTBUILD, + 'aborted': hudson_model.ABORTED} + sounds = XML.SubElement(xml_parent, 'net.hurstfrost.hudson.' + 'sounds.HudsonSoundsNotifier') + events = XML.SubElement(sounds, 'soundEvents') + for status, v in data.items(): + try: + model = mapping_dict[status] + except KeyError: + raise InvalidAttributeError('build status', status, mapping_dict) + + event = XML.SubElement(events, + 'net.hurstfrost.hudson.sounds.' + 'HudsonSoundsNotifier_-SoundEvent') + XML.SubElement(event, 'soundId').text = v['sound'] + to_result = XML.SubElement(event, 'toResult') + XML.SubElement(to_result, 'name').text = model['name'] + XML.SubElement(to_result, 'ordinal').text = model['ordinal'] + XML.SubElement(to_result, 'color').text = model['color'] + XML.SubElement(to_result, 'completeBuild').text = str( + model['complete']).lower() + + from_results = XML.SubElement(event, 'fromResults') + results = ['not_build', 'success', 'aborted', 'failure', 'unstable'] + if 'from' in v: + results = v['from'] + for result in results: + model = mapping_dict[result] + from_result = XML.SubElement(from_results, 'hudson.model.Result') + XML.SubElement(from_result, 'name').text = model['name'] + XML.SubElement(from_result, 'ordinal').text = model['ordinal'] + XML.SubElement(from_result, 'color').text = model['color'] + XML.SubElement(from_result, 'completeBuild').text = str( + model['complete']).lower() + + def performance(registry, xml_parent, data): """yaml: performance Publish performance test results from jmeter and junit. diff --git a/tests/publishers/fixtures/sounds001.xml b/tests/publishers/fixtures/sounds001.xml new file mode 100644 index 000000000..85c1290b2 --- /dev/null +++ b/tests/publishers/fixtures/sounds001.xml @@ -0,0 +1,50 @@ + + + + + + + EXPLODE + + FAILURE + 2 + RED + true + + + + NOT_BUILD + 3 + NOTBUILD + false + + + SUCCESS + 0 + BLUE + true + + + ABORTED + 4 + ABORTED + false + + + FAILURE + 2 + RED + true + + + UNSTABLE + 1 + YELLOW + true + + + + + + + diff --git a/tests/publishers/fixtures/sounds001.yaml b/tests/publishers/fixtures/sounds001.yaml new file mode 100644 index 000000000..6d609bf00 --- /dev/null +++ b/tests/publishers/fixtures/sounds001.yaml @@ -0,0 +1,4 @@ +publishers: +- sounds: + failure: + sound: EXPLODE diff --git a/tests/publishers/fixtures/sounds002.xml b/tests/publishers/fixtures/sounds002.xml new file mode 100644 index 000000000..85c1290b2 --- /dev/null +++ b/tests/publishers/fixtures/sounds002.xml @@ -0,0 +1,50 @@ + + + + + + + EXPLODE + + FAILURE + 2 + RED + true + + + + NOT_BUILD + 3 + NOTBUILD + false + + + SUCCESS + 0 + BLUE + true + + + ABORTED + 4 + ABORTED + false + + + FAILURE + 2 + RED + true + + + UNSTABLE + 1 + YELLOW + true + + + + + + + diff --git a/tests/publishers/fixtures/sounds002.yaml b/tests/publishers/fixtures/sounds002.yaml new file mode 100644 index 000000000..b0989b613 --- /dev/null +++ b/tests/publishers/fixtures/sounds002.yaml @@ -0,0 +1,10 @@ +publishers: +- sounds: + failure: + sound: EXPLODE + from: + - not_build + - success + - aborted + - failure + - unstable diff --git a/tests/publishers/fixtures/sounds003.xml b/tests/publishers/fixtures/sounds003.xml new file mode 100644 index 000000000..2caf18322 --- /dev/null +++ b/tests/publishers/fixtures/sounds003.xml @@ -0,0 +1,61 @@ + + + + + + + EXPLODE + + FAILURE + 2 + RED + true + + + + NOT_BUILD + 3 + NOTBUILD + false + + + ABORTED + 4 + ABORTED + false + + + + + Yahoo.Yodel + + SUCCESS + 0 + BLUE + true + + + + UNSTABLE + 1 + YELLOW + true + + + SUCCESS + 0 + BLUE + true + + + FAILURE + 2 + RED + true + + + + + + + diff --git a/tests/publishers/fixtures/sounds003.yaml b/tests/publishers/fixtures/sounds003.yaml new file mode 100644 index 000000000..01113372c --- /dev/null +++ b/tests/publishers/fixtures/sounds003.yaml @@ -0,0 +1,13 @@ +publishers: +- sounds: + failure: + sound: EXPLODE + from: + - not_build + - aborted + success: + sound: Yahoo.Yodel + from: + - unstable + - success + - failure