diff --git a/doc/source/reference/drivers/mqtt.rst b/doc/source/reference/drivers/mqtt.rst index 68dfd9d0ad..be8fe67738 100644 --- a/doc/source/reference/drivers/mqtt.rst +++ b/doc/source/reference/drivers/mqtt.rst @@ -128,6 +128,26 @@ An MQTT report uses this schema: The build results (not present in start report). + .. attr:: artifacts + :type: list + + The build artifacts (not present in start report). + + This is a list of dictionaries corresponding to the returned artifacts. + + .. attr:: name + + The name of the artifact. + + .. attr:: url + + The url of the artifact. + + .. attr:: metadata + :type: dict + + The metadata of the artifact. This is a dictionary of + arbitrary key values determined by the job. Here is an example of a start message: @@ -191,7 +211,8 @@ Here is an example of a success message: 'log_url': 'https://logs.example.com/logs/3/3/1/check/linters/16e3e55/', 'web_url': 'https://tenant.example.com/t/tenant-one/build/16e3e55aca984c6c9a50cc3c5b21bb83/', 'result': 'SUCCESS', - 'dependencies': [] + 'dependencies': [], + 'artifacts': [], }], }, } diff --git a/releasenotes/notes/mqtt-artifacts-4bdd3a8a7f7e3f33.yaml b/releasenotes/notes/mqtt-artifacts-4bdd3a8a7f7e3f33.yaml new file mode 100644 index 0000000000..9ffe70f45d --- /dev/null +++ b/releasenotes/notes/mqtt-artifacts-4bdd3a8a7f7e3f33.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + The MQTT reporter now includes artifact information along with build results. diff --git a/tests/unit/test_connection.py b/tests/unit/test_connection.py index 570fd052d8..d78342e3cf 100644 --- a/tests/unit/test_connection.py +++ b/tests/unit/test_connection.py @@ -586,8 +586,15 @@ class TestMQTTConnection(ZuulTestCase): "Test the MQTT reporter" # Add a success result A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') + artifact = {'name': 'image', + 'url': 'http://example.com/image', + 'metadata': { + 'type': 'container_image' + }} self.executor_server.returnData( - "test", A, {"zuul": {"log_url": "some-log-url"}} + "test", A, {"zuul": {"log_url": "some-log-url", + 'artifacts': [artifact], + }} ) self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) self.waitUntilSettled() @@ -606,6 +613,7 @@ class TestMQTTConnection(ZuulTestCase): self.assertEquals(mqtt_payload['buildset']['builds'][0]['job_name'], 'test') self.assertNotIn('result', mqtt_payload['buildset']['builds'][0]) + self.assertNotIn('artifacts', mqtt_payload['buildset']['builds'][0]) self.assertEquals(success_event.get('topic'), 'tenant-one/zuul_buildset/check/org/project/master') @@ -621,6 +629,7 @@ class TestMQTTConnection(ZuulTestCase): self.assertEquals(test_job['job_name'], 'test') self.assertEquals(test_job['result'], 'SUCCESS') self.assertEquals(test_job['dependencies'], []) + self.assertEquals(test_job['artifacts'], [artifact]) # Both log- and web-url should point to the same URL which is specified # in the build result data under zuul.log_url. self.assertEquals(test_job['log_url'], 'some-log-url/') diff --git a/zuul/driver/mqtt/mqttreporter.py b/zuul/driver/mqtt/mqttreporter.py index e489f5908a..3376f18666 100644 --- a/zuul/driver/mqtt/mqttreporter.py +++ b/zuul/driver/mqtt/mqttreporter.py @@ -17,6 +17,7 @@ import time import voluptuous as v from zuul.lib.logutil import get_annotated_logger +from zuul.lib.result_data import get_artifacts_from_result_data from zuul.reporter import BaseReporter @@ -73,7 +74,10 @@ class MQTTReporter(BaseReporter): 'web_url': web_url, 'result': result, 'dependencies': [j.name for j in job.dependencies], + 'artifacts': get_artifacts_from_result_data( + build.result_data, logger=log) }) + # Report build data of retried builds if available retry_builds = item.current_build_set.getRetryBuildsForJob( job.name)