From 3979e3e31ccbf3496679d78bb35397f570437449 Mon Sep 17 00:00:00 2001 From: Joshua Hesketh Date: Tue, 4 Mar 2014 11:21:10 +1100 Subject: [PATCH] Add configurable footer-message reports Currently there is no way to add extra information to the end of a report sent back by zuul. This adds a 'footer-message' field to the pipelines allowing operators to leave extra information at the end of a build result. This is useful for leaving CI contact and debugging information. Change-Id: Ieae62e845915fa3997353b6b425e215966a9338c --- doc/source/zuul.rst | 5 +++ tests/fixtures/layout-footer-message.yaml | 34 +++++++++++++++++++ tests/test_scheduler.py | 40 +++++++++++++++++++++++ zuul/layoutvalidator.py | 1 + zuul/model.py | 1 + zuul/scheduler.py | 3 ++ 6 files changed, 84 insertions(+) create mode 100644 tests/fixtures/layout-footer-message.yaml diff --git a/doc/source/zuul.rst b/doc/source/zuul.rst index 1a6a23de9b..7b6a7ccd91 100644 --- a/doc/source/zuul.rst +++ b/doc/source/zuul.rst @@ -238,6 +238,11 @@ explanation of each of the parameters:: reported back to Gerrit when at least one voting build fails. Defaults to "Build failed." +**footer-message** + An optional field to supply additional information after test results. + Useful for adding information about the CI system such as debugging + and contact details. + **manager** There are currently two schemes for managing pipelines: diff --git a/tests/fixtures/layout-footer-message.yaml b/tests/fixtures/layout-footer-message.yaml new file mode 100644 index 0000000000..7977c19bc8 --- /dev/null +++ b/tests/fixtures/layout-footer-message.yaml @@ -0,0 +1,34 @@ +includes: + - python-file: custom_functions.py + +pipelines: + - name: gate + manager: DependentPipelineManager + failure-message: Build failed. For information on how to proceed, see http://wiki.example.org/Test_Failures + footer-message: For CI problems and help debugging, contact ci@example.org + trigger: + gerrit: + - event: comment-added + approval: + - approved: 1 + success: + gerrit: + verified: 2 + submit: true + smtp: + to: success@example.org + failure: + gerrit: + verified: -2 + smtp: + to: failure@example.org + start: + gerrit: + verified: 0 + precedence: high + +projects: + - name: org/project + gate: + - test1 + - test2 diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index 95764404e6..f3d0e15b2f 100755 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -3640,3 +3640,43 @@ class TestScheduler(testtools.TestCase): self.worker.hold_jobs_in_build = False self.worker.release() self.waitUntilSettled() + + def test_footer_message(self): + "Test a pipeline's footer message is correctly added to the report." + self.config.set('zuul', 'layout_config', + 'tests/fixtures/layout-footer-message.yaml') + self.sched.reconfigure(self.config) + self.registerJobs() + + A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') + A.addApproval('CRVW', 2) + self.worker.addFailTest('test1', A) + self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) + self.waitUntilSettled() + + B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') + B.addApproval('CRVW', 2) + self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) + self.waitUntilSettled() + + self.assertEqual(2, len(self.smtp_messages)) + + failure_body = """\ +Build failed. For information on how to proceed, see \ +http://wiki.example.org/Test_Failures + +- test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s +- test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s + +For CI problems and help debugging, contact ci@example.org""" + + success_body = """\ +Build succeeded. + +- test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s +- test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s + +For CI problems and help debugging, contact ci@example.org""" + + self.assertEqual(failure_body, self.smtp_messages[0]['body']) + self.assertEqual(success_body, self.smtp_messages[1]['body']) diff --git a/zuul/layoutvalidator.py b/zuul/layoutvalidator.py index 48aab03490..de58c251e0 100644 --- a/zuul/layoutvalidator.py +++ b/zuul/layoutvalidator.py @@ -79,6 +79,7 @@ class LayoutSchema(object): 'description': str, 'success-message': str, 'failure-message': str, + 'footer-message': str, 'dequeue-on-new-patchset': bool, 'trigger': trigger, 'success': report_actions, diff --git a/zuul/model.py b/zuul/model.py index a90c6f7483..b20c08ea29 100644 --- a/zuul/model.py +++ b/zuul/model.py @@ -64,6 +64,7 @@ class Pipeline(object): self.description = None self.failure_message = None self.success_message = None + self.footer_message = None self.dequeue_on_new_patchset = True self.job_trees = {} # project -> JobTree self.manager = None diff --git a/zuul/scheduler.py b/zuul/scheduler.py index 815da8c776..ac9974057d 100644 --- a/zuul/scheduler.py +++ b/zuul/scheduler.py @@ -228,6 +228,7 @@ class Scheduler(threading.Thread): "Build failed.") pipeline.success_message = conf_pipeline.get('success-message', "Build succeeded.") + pipeline.footer_message = conf_pipeline.get('footer-message', "") pipeline.dequeue_on_new_patchset = conf_pipeline.get( 'dequeue-on-new-patchset', True) @@ -1438,6 +1439,8 @@ class BasePipelineManager(object): name = job.name + ' ' ret += '- %s%s : %s%s%s\n' % (name, url, result, elapsed, voting) + ret += '\n' + ret += self.pipeline.footer_message return ret def formatDescription(self, build):