From 6513454265720b5a911271c70cfc7c36000abeca Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Wed, 16 Apr 2014 09:05:46 +0100 Subject: [PATCH] Adding global try/catch in Builder, in hope of fixing forever-hanging. Closes #354, Closes #304 --- PHPCI/Builder.php | 66 ++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index b7b8c77e..04c5c48e 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -188,41 +188,47 @@ class Builder implements LoggerAwareInterface $this->build->sendStatusPostback(); $this->success = true; - // Set up the build: - $this->setupBuild(); + try { + // Set up the build: + $this->setupBuild(); - // Run the core plugin stages: - foreach (array('setup', 'test') as $stage) { - $this->success &= $this->pluginExecutor->executePlugins($this->config, $stage); - } + // Run the core plugin stages: + foreach (array('setup', 'test') as $stage) { + $this->success &= $this->pluginExecutor->executePlugins($this->config, $stage); + } - // Set the status so this can be used by complete, success and failure - // stages. - if ($this->success) { - $this->build->setStatus(Build::STATUS_SUCCESS); - } else { + // Set the status so this can be used by complete, success and failure + // stages. + if ($this->success) { + $this->build->setStatus(Build::STATUS_SUCCESS); + } else { + $this->build->setStatus(Build::STATUS_FAILED); + } + + // Complete stage plugins are always run + $this->pluginExecutor->executePlugins($this->config, 'complete'); + + if ($this->success) { + $this->pluginExecutor->executePlugins($this->config, 'success'); + $this->buildLogger->logSuccess('BUILD SUCCESSFUL!'); + } else { + $this->pluginExecutor->executePlugins($this->config, 'failure'); + $this->buildLogger->logFailure("BUILD FAILURE"); + } + + // Clean up: + $this->buildLogger->log('Removing build.'); + + $cmd = 'rm -Rf "%s"'; + if (IS_WIN) { + $cmd = 'rmdir /S /Q "%s"'; + } + $this->executeCommand($cmd, $this->buildPath); + } catch (\Exception $ex) { $this->build->setStatus(Build::STATUS_FAILED); + $this->buildLogger->logFailure('Exception: ' . $ex->getMessage()); } - // Complete stage plugins are always run - $this->pluginExecutor->executePlugins($this->config, 'complete'); - - if ($this->success) { - $this->pluginExecutor->executePlugins($this->config, 'success'); - $this->buildLogger->logSuccess('BUILD SUCCESSFUL!'); - } else { - $this->pluginExecutor->executePlugins($this->config, 'failure'); - $this->buildLogger->logFailure("BUILD FAILURE"); - } - - // Clean up: - $this->buildLogger->log('Removing build.'); - - $cmd = 'rm -Rf "%s"'; - if (IS_WIN) { - $cmd = 'rmdir /S /Q "%s"'; - } - $this->executeCommand($cmd, $this->buildPath); // Update the build in the database, ping any external services, etc. $this->build->sendStatusPostback();