Merge "Add no-jobs reporter action"

This commit is contained in:
Zuul 2019-09-18 08:36:43 +00:00 committed by Gerrit Code Review
commit cb51f8843e
6 changed files with 40 additions and 3 deletions

View File

@ -259,6 +259,11 @@ success, the pipeline reports back to Gerrit with ``Verified`` vote of
fails to merge with the current state of the repository. fails to merge with the current state of the repository.
Defaults to "Merge failed." Defaults to "Merge failed."
.. attr:: no-jobs-message
The introductory text in reports when an item is dequeued
without running any jobs. Empty by default.
.. attr:: footer-message .. attr:: footer-message
Supplies additional information after test results. Useful for Supplies additional information after test results. Useful for
@ -382,6 +387,13 @@ success, the pipeline reports back to Gerrit with ``Verified`` vote of
running for an item in the pipeline. This can be used, for running for an item in the pipeline. This can be used, for
example, to reset a previously reported result. example, to reset a previously reported result.
.. attr:: no-jobs
These reporters describe what Zuul should do when an item is
dequeued from a pipeline without running any jobs. This may be
used to indicate to a system or user that the pipeline is not
relevant for a change.
.. attr:: disabled .. attr:: disabled
These reporters describe what Zuul should do when a pipeline is These reporters describe what Zuul should do when a pipeline is

View File

@ -0,0 +1,6 @@
---
features:
- |
Added the :attr:`pipeline.no-jobs` reporter action so that
reporters may be run when an item is dequeued into a pipeline
without having run any jobs.

View File

@ -1124,6 +1124,7 @@ class PipelineParser(object):
'success': 'success_actions', 'success': 'success_actions',
'failure': 'failure_actions', 'failure': 'failure_actions',
'merge-failure': 'merge_failure_actions', 'merge-failure': 'merge_failure_actions',
'no-jobs': 'no_jobs_actions',
'disabled': 'disabled_actions', 'disabled': 'disabled_actions',
} }
@ -1171,6 +1172,7 @@ class PipelineParser(object):
'failure-message': str, 'failure-message': str,
'start-message': str, 'start-message': str,
'merge-failure-message': str, 'merge-failure-message': str,
'no-jobs-message': str,
'footer-message': str, 'footer-message': str,
'dequeue-on-new-patchset': bool, 'dequeue-on-new-patchset': bool,
'ignore-dependencies': bool, 'ignore-dependencies': bool,
@ -1190,7 +1192,7 @@ class PipelineParser(object):
pipeline['reject'] = self.getDriverSchema('reject') pipeline['reject'] = self.getDriverSchema('reject')
pipeline['trigger'] = vs.Required(self.getDriverSchema('trigger')) pipeline['trigger'] = vs.Required(self.getDriverSchema('trigger'))
for action in ['enqueue', 'start', 'success', 'failure', for action in ['enqueue', 'start', 'success', 'failure',
'merge-failure', 'disabled']: 'merge-failure', 'no-jobs', 'disabled']:
pipeline[action] = self.getDriverSchema('reporter') pipeline[action] = self.getDriverSchema('reporter')
return vs.Schema(pipeline) return vs.Schema(pipeline)
@ -1218,6 +1220,7 @@ class PipelineParser(object):
pipeline.start_message = conf.get('start-message', pipeline.start_message = conf.get('start-message',
"Starting {pipeline.name} jobs.") "Starting {pipeline.name} jobs.")
pipeline.enqueue_message = conf.get('enqueue-message', "") pipeline.enqueue_message = conf.get('enqueue-message', "")
pipeline.no_jobs_message = conf.get('no-jobs-message', "")
pipeline.dequeue_on_new_patchset = conf.get( pipeline.dequeue_on_new_patchset = conf.get(
'dequeue-on-new-patchset', True) 'dequeue-on-new-patchset', True)
pipeline.ignore_dependencies = conf.get( pipeline.ignore_dependencies = conf.get(

View File

@ -1113,7 +1113,8 @@ class PipelineManager(object):
log.debug("Project %s not in pipeline %s for change %s", log.debug("Project %s not in pipeline %s for change %s",
item.change.project, self.pipeline, item.change) item.change.project, self.pipeline, item.change)
project_in_pipeline = False project_in_pipeline = False
actions = [] actions = self.pipeline.no_jobs_actions
item.setReportedResult('NO_JOBS')
elif item.getConfigErrors(): elif item.getConfigErrors():
log.debug("Invalid config for change %s", item.change) log.debug("Invalid config for change %s", item.change)
# TODOv3(jeblair): consider a new reporter action for this # TODOv3(jeblair): consider a new reporter action for this
@ -1128,7 +1129,8 @@ class PipelineManager(object):
elif not item.getJobs(): elif not item.getJobs():
# We don't send empty reports with +1 # We don't send empty reports with +1
log.debug("No jobs for change %s", item.change) log.debug("No jobs for change %s", item.change)
actions = [] actions = self.pipeline.no_jobs_actions
item.setReportedResult('NO_JOBS')
elif item.didAllJobsSucceed(): elif item.didAllJobsSucceed():
log.debug("success %s", self.pipeline.success_actions) log.debug("success %s", self.pipeline.success_actions)
actions = self.pipeline.success_actions actions = self.pipeline.success_actions

View File

@ -273,6 +273,7 @@ class Pipeline(object):
self.success_actions = [] self.success_actions = []
self.failure_actions = [] self.failure_actions = []
self.merge_failure_actions = [] self.merge_failure_actions = []
self.no_jobs_actions = []
self.disabled_actions = [] self.disabled_actions = []
self.disable_at = None self.disable_at = None
self._consecutive_failures = 0 self._consecutive_failures = 0
@ -292,6 +293,7 @@ class Pipeline(object):
self.success_actions + self.success_actions +
self.failure_actions + self.failure_actions +
self.merge_failure_actions + self.merge_failure_actions +
self.no_jobs_actions +
self.disabled_actions self.disabled_actions
) )

View File

@ -104,6 +104,7 @@ class BaseReporter(object, metaclass=abc.ABCMeta):
'success': self._formatItemReportSuccess, 'success': self._formatItemReportSuccess,
'failure': self._formatItemReportFailure, 'failure': self._formatItemReportFailure,
'merge-failure': self._formatItemReportMergeFailure, 'merge-failure': self._formatItemReportMergeFailure,
'no-jobs': self._formatItemReportNoJobs,
'disabled': self._formatItemReportDisabled 'disabled': self._formatItemReportDisabled
} }
return format_methods[self._action] return format_methods[self._action]
@ -170,6 +171,17 @@ class BaseReporter(object, metaclass=abc.ABCMeta):
def _formatItemReportMergeFailure(self, item, with_jobs=True): def _formatItemReportMergeFailure(self, item, with_jobs=True):
return item.pipeline.merge_failure_message return item.pipeline.merge_failure_message
def _formatItemReportNoJobs(self, item, with_jobs=True):
status_url = get_default(self.connection.sched.config,
'web', 'status_url', '')
if status_url:
status_url = item.formatUrlPattern(status_url)
return item.pipeline.no_jobs_message.format(
pipeline=item.pipeline.getSafeAttributes(),
change=item.change.getSafeAttributes(),
status_url=status_url)
def _formatItemReportDisabled(self, item, with_jobs=True): def _formatItemReportDisabled(self, item, with_jobs=True):
if item.current_build_set.result == 'SUCCESS': if item.current_build_set.result == 'SUCCESS':
return self._formatItemReportSuccess(item) return self._formatItemReportSuccess(item)