diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py index c1734c31c..e0be44150 100644 --- a/jenkins_jobs/modules/triggers.py +++ b/jenkins_jobs/modules/triggers.py @@ -777,6 +777,70 @@ def pollurl(registry, xml_parent, data): 'ContentEntry', *content_type[0:3]) +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 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 selector: The JSON or YAML formatted text that conforms to + the schema for defining the various OpenShift resources. (default '') + note: topic needs to be in double quotes + ex. topic = "org.fedoraproject.prod.fedimg.image.upload" + :arg str provider-name: Name of message provider setup in the + global config. (default '') + :arg list checks: List of checks to monitor. (default []) + :arg str field: Check the body of messages for a field. (default '') + :arg str expected-value: Expected value for the field. regex (default '') + + + Full Example: + + .. literalinclude:: + ../../tests/triggers/fixtures/jms-messaging001.yaml + :language: yaml + + Minimal Example: + + .. literalinclude:: + ../../tests/triggers/fixtures/jms-messaging002.yaml + :language: yaml + """ + namespace = 'com.redhat.jenkins.plugins.ci.' + jmsm = XML.SubElement(xml_parent, + namespace + 'CIBuildTrigger') + + mapping = [ + # option, xml name, default value + ("spec", 'spec', ''), + ("selector", 'selector', ''), + ("provider-name", 'providerName', ''), + ] + convert_mapping_to_xml(jmsm, data, mapping, fail_required=True) + + checks = data.get('checks', []) + if len(checks) > 0: + msgchecks = XML.SubElement(jmsm, 'checks') + for check in checks: + msgcheck = XML.SubElement(msgchecks, namespace + + 'messaging.checks.MsgCheck') + if check['field'] is '': + raise JenkinsJobsException('At least one ' + 'field must be provided') + XML.SubElement(msgcheck, 'field').text = check['field'] + XML.SubElement(msgcheck, + 'expectedValue').text = check['expected-value'] + + def timed(registry, xml_parent, data): """yaml: timed Trigger builds at certain times. diff --git a/tests/triggers/fixtures/jms-messaging001.xml b/tests/triggers/fixtures/jms-messaging001.xml new file mode 100644 index 000000000..9c45a8bd5 --- /dev/null +++ b/tests/triggers/fixtures/jms-messaging001.xml @@ -0,0 +1,20 @@ + + + + + + topic = "org.fedoraproject.prod.fedimg.image.upload" + fedmsg + + + compose + .+compose_id.+Fedora-Atomic.+ + + + image_name + .+Fedora-Atomic.+ + + + + + \ No newline at end of file diff --git a/tests/triggers/fixtures/jms-messaging001.yaml b/tests/triggers/fixtures/jms-messaging001.yaml new file mode 100644 index 000000000..2e9d4b776 --- /dev/null +++ b/tests/triggers/fixtures/jms-messaging001.yaml @@ -0,0 +1,9 @@ +triggers: + - jms-messaging: + selector: topic = "org.fedoraproject.prod.fedimg.image.upload" + provider-name: fedmsg + checks: + - field: compose + expected-value: .+compose_id.+Fedora-Atomic.+ + - field: image_name + expected-value: .+Fedora-Atomic.+ diff --git a/tests/triggers/fixtures/jms-messaging002.xml b/tests/triggers/fixtures/jms-messaging002.xml new file mode 100644 index 000000000..d0b6c23cd --- /dev/null +++ b/tests/triggers/fixtures/jms-messaging002.xml @@ -0,0 +1,10 @@ + + + + + + topic = "org.fedoraproject.prod.fedimg.image.upload" + fedmsg + + + \ No newline at end of file diff --git a/tests/triggers/fixtures/jms-messaging002.yaml b/tests/triggers/fixtures/jms-messaging002.yaml new file mode 100644 index 000000000..36e5085b1 --- /dev/null +++ b/tests/triggers/fixtures/jms-messaging002.yaml @@ -0,0 +1,5 @@ +triggers: + - jms-messaging: + selector: topic = "org.fedoraproject.prod.fedimg.image.upload" + provider-name: fedmsg +