Add trigger metadata (which includes the SHA) and the built image_id to the event data

This commit is contained in:
Joseph Schorr 2015-02-24 15:13:51 -05:00
parent a7ddf46c2a
commit b7901d2adb
3 changed files with 43 additions and 8 deletions

View file

@ -247,12 +247,22 @@ class BuildComponent(BaseComponent):
""" Wraps up a completed build. Handles any errors and calls self._build_finished. """
try:
# Retrieve the result. This will raise an ApplicationError on any error that occurred.
result.result()
result_value = result.result()
kwargs = {}
# Note: If we are hitting an older builder that didn't return ANY map data, then the result
# value will be a bool instead of a proper CallResult object (because autobahn sucks).
# Therefore: we have a try-except guard here to ensure we don't hit this pitfall.
try:
kwargs = result_value.kwresults
except:
pass
self._build_status.set_phase(BUILD_PHASE.COMPLETE)
trollius.async(self._build_finished(BuildJobResult.COMPLETE))
# Send the notification that the build has completed successfully.
self._current_job.send_notification('build_success')
self._current_job.send_notification('build_success', image_id=kwargs.get('image_id'))
except ApplicationError as aex:
worker_error = WorkerError(aex.error, aex.kwargs.get('base_error'))

View file

@ -28,16 +28,20 @@ class BuildJob(object):
def has_retries_remaining(self):
return self.job_item.retries_remaining > 0
def send_notification(self, kind, error_message=None):
def send_notification(self, kind, error_message=None, image_id=None):
tags = self.build_config.get('docker_tags', ['latest'])
event_data = {
'build_id': self.repo_build.uuid,
'build_name': self.repo_build.display_name,
'docker_tags': tags,
'trigger_id': self.repo_build.trigger.uuid,
'trigger_kind': self.repo_build.trigger.service.name
'trigger_kind': self.repo_build.trigger.service.name,
'trigger_metadata': self.build_config.get('trigger_metadata', {})
}
if image_id is not None:
event_data['image_id'] = image_id
if error_message is not None:
event_data['error_message'] = error_message

View file

@ -92,7 +92,12 @@ class BuildQueueEvent(NotificationEvent):
'build_id': build_uuid,
'build_name': 'some-fake-build',
'docker_tags': ['latest', 'foo', 'bar'],
'trigger_kind': 'GitHub'
'trigger_kind': 'GitHub',
'trigger_metadata': {
"default_branch": "master",
"ref": "refs/heads/somebranch",
"commit_sha": "42d4a62c53350993ea41069e9f2cfdefb0df097d"
}
}, subpage='/build?current=%s' % build_uuid)
def get_summary(self, event_data, notification_data):
@ -114,7 +119,12 @@ class BuildStartEvent(NotificationEvent):
'build_id': build_uuid,
'build_name': 'some-fake-build',
'docker_tags': ['latest', 'foo', 'bar'],
'trigger_kind': 'GitHub'
'trigger_kind': 'GitHub',
'trigger_metadata': {
"default_branch": "master",
"ref": "refs/heads/somebranch",
"commit_sha": "42d4a62c53350993ea41069e9f2cfdefb0df097d"
}
}, subpage='/build?current=%s' % build_uuid)
def get_summary(self, event_data, notification_data):
@ -136,7 +146,13 @@ class BuildSuccessEvent(NotificationEvent):
'build_id': build_uuid,
'build_name': 'some-fake-build',
'docker_tags': ['latest', 'foo', 'bar'],
'trigger_kind': 'GitHub'
'trigger_kind': 'GitHub',
'trigger_metadata': {
"default_branch": "master",
"ref": "refs/heads/somebranch",
"commit_sha": "42d4a62c53350993ea41069e9f2cfdefb0df097d"
},
'image_id': '1245657346'
}, subpage='/build?current=%s' % build_uuid)
def get_summary(self, event_data, notification_data):
@ -159,7 +175,12 @@ class BuildFailureEvent(NotificationEvent):
'build_name': 'some-fake-build',
'docker_tags': ['latest', 'foo', 'bar'],
'trigger_kind': 'GitHub',
'error_message': 'This is a fake error message'
'error_message': 'This is a fake error message',
'trigger_metadata': {
"default_branch": "master",
"ref": "refs/heads/somebranch",
"commit_sha": "42d4a62c53350993ea41069e9f2cfdefb0df097d"
}
}, subpage='/build?current=%s' % build_uuid)
def get_summary(self, event_data, notification_data):