Add artifacts to MQTT reporter

The MQTT reporter now includes artifacts for completed builds.  Systems
which watch for MQTT events can now directly consume those artifacts without
the intermediate step of looking them up via the API.

Change-Id: I9df9e1dfd6854518c110dd65d4f89dea449c6fc0
This commit is contained in:
James E. Blair 2021-04-26 17:09:44 -07:00
parent 8009b73578
commit 0bb697f1fc
4 changed files with 40 additions and 2 deletions

View File

@ -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': [],
}],
},
}

View File

@ -0,0 +1,4 @@
---
features:
- |
The MQTT reporter now includes artifact information along with build results.

View File

@ -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/')

View File

@ -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)