From a5eb235881c2848d258fb06eae4a60a1b83edd4b Mon Sep 17 00:00:00 2001 From: mhuin Date: Wed, 1 Feb 2017 15:58:30 +0100 Subject: [PATCH] Add a publisher for MQTT Add support for the MQTT Notification Plugin (https://wiki.jenkins-ci.org/display/JENKINS/MQTT+Notification+Plugin) Change-Id: Ibe867a15f5621601a45c2e1d6281f4db67df29d7 --- jenkins_jobs/modules/publishers.py | 46 +++++++++++++++++++++ tests/publishers/fixtures/mqtt-full.xml | 13 ++++++ tests/publishers/fixtures/mqtt-full.yaml | 8 ++++ tests/publishers/fixtures/mqtt-minimal.xml | 12 ++++++ tests/publishers/fixtures/mqtt-minimal.yaml | 3 ++ 5 files changed, 82 insertions(+) create mode 100644 tests/publishers/fixtures/mqtt-full.xml create mode 100644 tests/publishers/fixtures/mqtt-full.yaml create mode 100644 tests/publishers/fixtures/mqtt-minimal.xml create mode 100644 tests/publishers/fixtures/mqtt-minimal.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 34f0325bd..18e7e041f 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -300,6 +300,52 @@ def campfire(registry, xml_parent, data): XML.SubElement(room, 'campfire reference="../../campfire"') +def mqtt(registry, xml_parent, data): + """yaml: mqtt + This plugin lets you send build notifications to a MQTT message queue. + Requires the :jenkins-wiki:`MQTT Notification Plugin + `. + + :arg str broker-url: the broker URL, as protocol://address:port (required) + :arg str credentials-id: credentials to use to connect to the broker + (optional) + :arg str topic: the message topic (default "jenkins/$PROJECT_URL") + :arg str message: the message itself (default "$BUILD_RESULT") + :arg str qos: one of AT_MOST_ONCE, AT_LEAST_ONCE, or EXACTLY_ONCE + (default AT_MOST_ONCE) + :arg bool retain-message: whether to resend message or not when a new + client connects (default false) + + Minimal Example: + + .. literalinclude:: /../../tests/publishers/fixtures/mqtt-minimal.yaml + :language: yaml + + Full Example: + + .. literalinclude:: /../../tests/publishers/fixtures/mqtt-full.yaml + :language: yaml + """ + + mqtt = XML.SubElement(xml_parent, + 'jenkins.plugins.mqttnotification.MqttNotifier') + mqtt.set('plugin', 'mqtt-notification-plugin') + mqtt_mapping = [ + ('broker-url', 'brokerUrl', None), ] + helpers.convert_mapping_to_xml(mqtt, data, mqtt_mapping, + fail_required=True) + mqtt_mapping = [ + ('credentials-id', 'credentialsId', None), + ('topic', 'topic', 'jenkins/$PROJECT_URL'), + ('message', 'message', '$BUILD_RESULT'), + ('qos', 'qos', 'AT_MOST_ONCE', {'AT_MOST_ONCE': '0', + 'AT_LEAST_ONCE': '1', + 'EXACTLY_ONCE': '2'}), + ('retain-message', 'retainMessage', False) + ] + helpers.convert_mapping_to_xml(mqtt, data, mqtt_mapping) + + def codecover(registry, xml_parent, data): """yaml: codecover This plugin allows you to capture code coverage report from CodeCover. diff --git a/tests/publishers/fixtures/mqtt-full.xml b/tests/publishers/fixtures/mqtt-full.xml new file mode 100644 index 000000000..59e28d8c9 --- /dev/null +++ b/tests/publishers/fixtures/mqtt-full.xml @@ -0,0 +1,13 @@ + + + + + tcp://localhost:1883 + abcde + hello + world + 2 + true + + + diff --git a/tests/publishers/fixtures/mqtt-full.yaml b/tests/publishers/fixtures/mqtt-full.yaml new file mode 100644 index 000000000..d1a680347 --- /dev/null +++ b/tests/publishers/fixtures/mqtt-full.yaml @@ -0,0 +1,8 @@ +publishers: + - mqtt: + broker-url: tcp://localhost:1883 + topic: hello + message: world + qos: EXACTLY_ONCE + retain-message: true + credentials-id: abcde diff --git a/tests/publishers/fixtures/mqtt-minimal.xml b/tests/publishers/fixtures/mqtt-minimal.xml new file mode 100644 index 000000000..f9eca587d --- /dev/null +++ b/tests/publishers/fixtures/mqtt-minimal.xml @@ -0,0 +1,12 @@ + + + + + tcp://localhost:1883 + jenkins/$PROJECT_URL + $BUILD_RESULT + 0 + false + + + diff --git a/tests/publishers/fixtures/mqtt-minimal.yaml b/tests/publishers/fixtures/mqtt-minimal.yaml new file mode 100644 index 000000000..ca8cfb982 --- /dev/null +++ b/tests/publishers/fixtures/mqtt-minimal.yaml @@ -0,0 +1,3 @@ +publishers: + - mqtt: + broker-url: tcp://localhost:1883