diff --git a/build.sh b/build.sh index 9a4c8aae0..12ec0faa7 100755 --- a/build.sh +++ b/build.sh @@ -1 +1,2 @@ -docker build -t quay.io/quay/quay:`git rev-parse --short HEAD` . \ No newline at end of file +docker build -t quay.io/quay/quay:`git rev-parse --short HEAD` . +echo quay.io/quay/quay:`git rev-parse --short HEAD` \ No newline at end of file diff --git a/buildman/component/buildcomponent.py b/buildman/component/buildcomponent.py index f43effb3a..795ab3924 100644 --- a/buildman/component/buildcomponent.py +++ b/buildman/component/buildcomponent.py @@ -74,11 +74,14 @@ class BuildComponent(BaseComponent): yield trollius.From(self._set_status(ComponentStatus.BUILDING)) + # Send the notification that the build has started. + build_job.send_notification('build_start') + # Retrieve the job's buildpack. buildpack_url = self.user_files.get_file_url(build_job.repo_build.resource_key, requires_cors=False) - logger.debug('Retreiving build package: %s', buildpack_url) + logger.debug('Retrieving build package: %s', buildpack_url) buildpack = None try: buildpack = BuildPackage.from_url(buildpack_url) @@ -262,6 +265,9 @@ class BuildComponent(BaseComponent): result.result() self._build_status.set_phase(BUILD_PHASE.COMPLETE) trollius.async(self._build_finished(BuildJobResult.COMPLETE)) + + # Send the notification that the build has completed successfully. + build_job.send_notification('build_success') except ApplicationError as aex: worker_error = WorkerError(aex.error, aex.kwargs.get('base_error')) @@ -269,6 +275,9 @@ class BuildComponent(BaseComponent): self._build_status.set_error(worker_error.public_message(), worker_error.extra_data(), internal_error=worker_error.is_internal_error()) + # Send the notification that the build has failed. + build_job.send_notification('build_failure', error_message=worker_error.public_message()) + # Mark the build as completed. if worker_error.is_internal_error(): trollius.async(self._build_finished(BuildJobResult.INCOMPLETE)) diff --git a/buildman/jobutil/buildjob.py b/buildman/jobutil/buildjob.py index d120417f7..b16201918 100644 --- a/buildman/jobutil/buildjob.py +++ b/buildman/jobutil/buildjob.py @@ -1,7 +1,7 @@ import json from cachetools import lru_cache - +from endpoints.notificationhelper import spawn_notification from data import model @@ -21,6 +21,24 @@ class BuildJob(object): 'Could not parse build queue item config with ID %s' % self.job_details['build_uuid'] ) + def send_notification(self, kind, error_message=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 + } + + if error_message is not None: + event_data['error_message'] = message + + spawn_notification(self.repo_build.repository, kind, event_data, + subpage='build?current=%s' % self.repo_build.uuid, + pathargs=['build', self.repo_build.uuid]) + + @lru_cache(maxsize=1) def _load_repo_build(self): try: