From 1979a954d1fed74f871c9e748c160c80fb0d2f3d Mon Sep 17 00:00:00 2001 From: Ari LiVigni Date: Thu, 11 May 2017 00:41:19 -0400 Subject: [PATCH] Add support for jms_messaging builder and publisher - Added the following for builder and publisher - Added all the fields for JMS Messaging plugins - Added a minimal example - Added a full example - Added info in trigger for builder description of the plugin Change-Id: Ifa209978dd38692da9f9d06bdf34782bd684a324 --- jenkins_jobs/modules/builders.py | 44 +++++++++++++++++++ jenkins_jobs/modules/helpers.py | 26 +++++++++++ jenkins_jobs/modules/publishers.py | 44 +++++++++++++++++++ jenkins_jobs/modules/triggers.py | 2 + .../builders/fixtures/jms-messaging-full.xml | 26 +++++++++++ .../builders/fixtures/jms-messaging-full.yaml | 20 +++++++++ .../fixtures/jms-messaging-minimal.xml | 11 +++++ .../fixtures/jms-messaging-minimal.yaml | 6 +++ .../fixtures/jms-messaging-full.xml | 26 +++++++++++ .../fixtures/jms-messaging-full.yaml | 20 +++++++++ .../fixtures/jms-messaging-minimal.xml | 11 +++++ .../fixtures/jms-messaging-minimal.yaml | 6 +++ 12 files changed, 242 insertions(+) create mode 100644 tests/builders/fixtures/jms-messaging-full.xml create mode 100644 tests/builders/fixtures/jms-messaging-full.yaml create mode 100644 tests/builders/fixtures/jms-messaging-minimal.xml create mode 100644 tests/builders/fixtures/jms-messaging-minimal.yaml create mode 100644 tests/publishers/fixtures/jms-messaging-full.xml create mode 100644 tests/publishers/fixtures/jms-messaging-full.yaml create mode 100644 tests/publishers/fixtures/jms-messaging-minimal.xml create mode 100644 tests/publishers/fixtures/jms-messaging-minimal.yaml diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index 33749db3e..bd6d97204 100644 --- a/jenkins_jobs/modules/builders.py +++ b/jenkins_jobs/modules/builders.py @@ -3254,6 +3254,50 @@ def cloudformation(registry, xml_parent, data): region_dict) +def jms_messaging(registry, xml_parent, data): + """yaml: jms-messaging + The JMS Messaging Plugin provides the following functionality: + - A build trigger to submit jenkins jobs upon receipt + of a matching message. + - A builder that may be used to submit a message to the topic + upon the completion of a job + - A post-build action that may be used to submit a message to the topic + upon the completion of a job + + + JMS Messaging provider types supported: + - ActiveMQ + - FedMsg + + Requires the Jenkins :jenkins-wiki:`JMS Messaging Plugin + Pipeline Plugin `. + + :arg str override-topic: If you need to override the default topic. + (default '') + :arg str provider-name: Name of message provider setup in the + global config. (default '') + :arg str msg-type: A message type + (default 'CodeQualityChecksDone') + :arg str msg-props: Message header to publish. (default '') + :arg str msg-content: Message body to publish. (default '') + + + Full Example: + + .. literalinclude:: + ../../tests/builders/fixtures/jms-messaging-full.yaml + :language: yaml + + Minimal Example: + + .. literalinclude:: + ../../tests/builders/fixtures/jms-messaging-minimal.yaml + :language: yaml + """ + helpers.jms_messaging_common(xml_parent, 'com.redhat.jenkins.plugins.ci.' + 'CIMessageBuilder', data) + + def openshift_build_verify(registry, xml_parent, data): """yaml: openshift-build-verify Performs the equivalent of an 'oc get builds` command invocation for the diff --git a/jenkins_jobs/modules/helpers.py b/jenkins_jobs/modules/helpers.py index bf0bb9f43..910d83243 100644 --- a/jenkins_jobs/modules/helpers.py +++ b/jenkins_jobs/modules/helpers.py @@ -522,3 +522,29 @@ def convert_mapping_to_xml(parent, data, mapping, fail_required=False): XML.SubElement(parent, xmlname).text = str(valid_dict[val]) else: XML.SubElement(parent, xmlname).text = str(val) + + +def jms_messaging_common(parent, subelement, data): + """JMS common helper function + + Pass the XML parent and the specific subelement from the builder or the + publisher. + + data is passed to mapper helper function to map yaml fields to XML fields + """ + namespace = XML.SubElement(parent, + subelement) + + if 'override-topic' in data: + overrides = XML.SubElement(namespace, 'overrides') + XML.SubElement(overrides, + 'topic').text = str(data.get('override-topic', '')) + + mapping = [ + # option, xml name, default value + ("provider-name", 'providerName', ''), + ("msg-type", 'messageType', 'CodeQualityChecksDone'), + ("msg-props", 'messageProperties', ''), + ("msg-content", 'messageContent', ''), + ] + convert_mapping_to_xml(namespace, data, mapping, fail_required=True) diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index a08242899..dc960957a 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -6652,6 +6652,50 @@ def phabricator(registry, xml_parent, data): data.get('comment-with-console-link-on-failure')).lower() +def jms_messaging(registry, xml_parent, data): + """yaml: jms-messaging + The JMS Messaging Plugin provides the following functionality: + - A build trigger to submit jenkins jobs upon receipt + of a matching message. + - A builder that may be used to submit a message to the topic + upon the completion of a job + - A post-build action that may be used to submit a message to the topic + upon the completion of a job + + + JMS Messaging provider types supported: + - ActiveMQ + - FedMsg + + Requires the Jenkins :jenkins-wiki:`JMS Messaging Plugin + Pipeline Plugin `. + + :arg str override-topic: If you need to override the default topic. + (default '') + :arg str provider-name: Name of message provider setup in the + global config. (default '') + :arg str msg-type: A message type + (default 'CodeQualityChecksDone') + :arg str msg-props: Message header to publish. (default '') + :arg str msg-content: Message body to publish. (default '') + + + Full Example: + + .. literalinclude:: + ../../tests/publishers/fixtures/jms-messaging-full.yaml + :language: yaml + + Minimal Example: + + .. literalinclude:: + ../../tests/publishers/fixtures/jms-messaging-minimal.yaml + :language: yaml + """ + helpers.jms_messaging_common(xml_parent, 'com.redhat.jenkins.plugins.ci.' + 'CIMessageNotifier', data) + + def openshift_build_canceller(registry, xml_parent, data): """yaml: openshift-build-canceller This action is intended to provide cleanup for a Jenkins job which failed diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py index e0be44150..68f4bcefe 100644 --- a/jenkins_jobs/modules/triggers.py +++ b/jenkins_jobs/modules/triggers.py @@ -782,6 +782,8 @@ def jms_messaging(registry, xml_parent, data): The JMS Messaging Plugin provides the following functionality: - A build trigger to submit jenkins jobs upon receipt of a matching message. + - A builder that may be used to submit a message to the topic + upon the completion of a job - A post-build action that may be used to submit a message to the topic upon the completion of a job diff --git a/tests/builders/fixtures/jms-messaging-full.xml b/tests/builders/fixtures/jms-messaging-full.xml new file mode 100644 index 000000000..061a8ec8d --- /dev/null +++ b/tests/builders/fixtures/jms-messaging-full.xml @@ -0,0 +1,26 @@ + + + + + + org.centos.stage.ci.pipeline.compose.complete + + fedmsg + Custom + topic=org.centos.prod.ci.pipeline.compose.complete +username=fedora-atomic + + { + "build_url": "${BUILD_URL}", + "compose_url": "<full-url-to-compose>", + "build_id": "${BUILD_ID}", + "ref": "fedora/rawhide/${basearch}/atomic-host", + "rev": "<sha of the commit from dist-git>", + "namespace": "rpms", + "repo": "php-simplepie", + "status": "<success/failure/aborted>", + "test_guidance": "<comma-separated-list-of-test-suites-to-run>"} +} + + + \ No newline at end of file diff --git a/tests/builders/fixtures/jms-messaging-full.yaml b/tests/builders/fixtures/jms-messaging-full.yaml new file mode 100644 index 000000000..51d06504a --- /dev/null +++ b/tests/builders/fixtures/jms-messaging-full.yaml @@ -0,0 +1,20 @@ +builders: + - jms-messaging: + override-topic: org.centos.stage.ci.pipeline.compose.complete + provider-name: fedmsg + msg-type: Custom + msg-props: | + topic=org.centos.prod.ci.pipeline.compose.complete + username=fedora-atomic + msg-content: | + { + "build_url": "${BUILD_URL}", + "compose_url": "", + "build_id": "${BUILD_ID}", + "ref": "fedora/rawhide/${basearch}/atomic-host", + "rev": "", + "namespace": "rpms", + "repo": "php-simplepie", + "status": "", + "test_guidance": ""} + } \ No newline at end of file diff --git a/tests/builders/fixtures/jms-messaging-minimal.xml b/tests/builders/fixtures/jms-messaging-minimal.xml new file mode 100644 index 000000000..6ce2925ce --- /dev/null +++ b/tests/builders/fixtures/jms-messaging-minimal.xml @@ -0,0 +1,11 @@ + + + + + fedmsg + CodeQualityChecksDone + test + test + + + \ No newline at end of file diff --git a/tests/builders/fixtures/jms-messaging-minimal.yaml b/tests/builders/fixtures/jms-messaging-minimal.yaml new file mode 100644 index 000000000..133a962dd --- /dev/null +++ b/tests/builders/fixtures/jms-messaging-minimal.yaml @@ -0,0 +1,6 @@ +builders: + - jms-messaging: + provider-name: fedmsg + msg-type: CodeQualityChecksDone + msg-props: test + msg-content: test \ No newline at end of file diff --git a/tests/publishers/fixtures/jms-messaging-full.xml b/tests/publishers/fixtures/jms-messaging-full.xml new file mode 100644 index 000000000..6549b0c32 --- /dev/null +++ b/tests/publishers/fixtures/jms-messaging-full.xml @@ -0,0 +1,26 @@ + + + + + + org.centos.stage.ci.pipeline.compose.complete + + fedmsg + Custom + topic=org.centos.prod.ci.pipeline.compose.complete +username=fedora-atomic + + { + "build_url": "${BUILD_URL}", + "compose_url": "<full-url-to-compose>", + "build_id": "${BUILD_ID}", + "ref": "fedora/rawhide/${basearch}/atomic-host", + "rev": "<sha of the commit from dist-git>", + "namespace": "rpms", + "repo": "php-simplepie", + "status": "<success/failure/aborted>", + "test_guidance": "<comma-separated-list-of-test-suites-to-run>"} +} + + + \ No newline at end of file diff --git a/tests/publishers/fixtures/jms-messaging-full.yaml b/tests/publishers/fixtures/jms-messaging-full.yaml new file mode 100644 index 000000000..610d82823 --- /dev/null +++ b/tests/publishers/fixtures/jms-messaging-full.yaml @@ -0,0 +1,20 @@ +publishers: + - jms-messaging: + override-topic: org.centos.stage.ci.pipeline.compose.complete + provider-name: fedmsg + msg-type: Custom + msg-props: | + topic=org.centos.prod.ci.pipeline.compose.complete + username=fedora-atomic + msg-content: | + { + "build_url": "${BUILD_URL}", + "compose_url": "", + "build_id": "${BUILD_ID}", + "ref": "fedora/rawhide/${basearch}/atomic-host", + "rev": "", + "namespace": "rpms", + "repo": "php-simplepie", + "status": "", + "test_guidance": ""} + } \ No newline at end of file diff --git a/tests/publishers/fixtures/jms-messaging-minimal.xml b/tests/publishers/fixtures/jms-messaging-minimal.xml new file mode 100644 index 000000000..98e636433 --- /dev/null +++ b/tests/publishers/fixtures/jms-messaging-minimal.xml @@ -0,0 +1,11 @@ + + + + + fedmsg + CodeQualityChecksDone + test + test + + + \ No newline at end of file diff --git a/tests/publishers/fixtures/jms-messaging-minimal.yaml b/tests/publishers/fixtures/jms-messaging-minimal.yaml new file mode 100644 index 000000000..3cf9ee2e9 --- /dev/null +++ b/tests/publishers/fixtures/jms-messaging-minimal.yaml @@ -0,0 +1,6 @@ +publishers: + - jms-messaging: + provider-name: fedmsg + msg-type: CodeQualityChecksDone + msg-props: test + msg-content: test \ No newline at end of file