diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 440c0d53..08fd3bed 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -159,37 +159,39 @@ class Builder implements LoggerAwareInterface, BuildLogger public function execute() { // Update the build in the database, ping any external services. - $this->build->setStatus(1); + $this->build->setStatus(Build::STATUS_RUNNING); $this->build->setStarted(new \DateTime()); $this->store->save($this->build); $this->build->sendStatusPostback(); $this->success = true; - try { - // Set up the build: - $this->setupBuild(); + // Set up the build: + $this->setupBuild(); - // Run the core plugin stages: - foreach (array('setup', 'test', 'complete') 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); + } - // Failed build? Execute failure plugins and then mark the build as failed. - if (!$this->success) { - $this->pluginExecutor->executePlugins($this->config, 'failure'); - throw new \Exception('BUILD FAILED!'); - } + // 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); + } - // If we got this far, the build was successful! - if ($this->success) { - $this->build->setStatus(2); - $this->pluginExecutor->executePlugins($this->config, 'success'); - $this->logSuccess('BUILD SUCCESSFUL!'); - } + // Complete stage plugins are always run + $this->pluginExecutor->executePlugins($this->config, 'complete'); - } catch (\Exception $ex) { - $this->logFailure($ex->getMessage(), $ex); - $this->build->setStatus(3); + if ($this->success) { + $this->pluginExecutor->executePlugins($this->config, 'success'); + $this->logSuccess('BUILD SUCCESSFUL!'); + } + else { + $this->pluginExecutor->executePlugins($this->config, 'failure'); + $this->logFailure("BUILD FAILURE"); } // Clean up: diff --git a/PHPCI/Command/PollCommand.php b/PHPCI/Command/PollCommand.php index af91acec..3918e27d 100644 --- a/PHPCI/Command/PollCommand.php +++ b/PHPCI/Command/PollCommand.php @@ -84,7 +84,7 @@ class PollCommand extends Command $build = new Build(); $build->setProjectId($project->getId()); $build->setCommitId($last_commit); - $build->setStatus(0); + $build->setStatus(Build::STATUS_NEW); $build->setBranch($project->getType() === 'hg' ? 'default' : 'master'); $build->setCreated(new \DateTime()); diff --git a/PHPCI/Controller/BitbucketController.php b/PHPCI/Controller/BitbucketController.php index 9ec4bb39..783421a3 100644 --- a/PHPCI/Controller/BitbucketController.php +++ b/PHPCI/Controller/BitbucketController.php @@ -53,7 +53,7 @@ class BitbucketController extends \PHPCI\Controller $build = new Build(); $build->setProjectId($project); $build->setCommitId($commits[$branch]); - $build->setStatus(0); + $build->setStatus(Build::STATUS_NEW); $build->setLog(''); $build->setCreated(new \DateTime()); $build->setBranch($branch); diff --git a/PHPCI/Controller/BuildController.php b/PHPCI/Controller/BuildController.php index f4a1d9c8..c80cb7c8 100644 --- a/PHPCI/Controller/BuildController.php +++ b/PHPCI/Controller/BuildController.php @@ -109,7 +109,7 @@ class BuildController extends \PHPCI\Controller $build = new Build(); $build->setProjectId($copy->getProjectId()); $build->setCommitId($copy->getCommitId()); - $build->setStatus(0); + $build->setStatus(Build::STATUS_NEW); $build->setBranch($copy->getBranch()); $build->setCreated(new \DateTime()); diff --git a/PHPCI/Controller/GitController.php b/PHPCI/Controller/GitController.php index 396ecaa9..b5a6cf87 100644 --- a/PHPCI/Controller/GitController.php +++ b/PHPCI/Controller/GitController.php @@ -47,7 +47,7 @@ class GitController extends \PHPCI\Controller $build->setCommitId($commit); } - $build->setStatus(0); + $build->setStatus(Build::STATUS_NEW); $build->setLog(''); $build->setCreated(new \DateTime()); } catch (\Exception $ex) { diff --git a/PHPCI/Controller/GithubController.php b/PHPCI/Controller/GithubController.php index b616cbb4..4fe99756 100644 --- a/PHPCI/Controller/GithubController.php +++ b/PHPCI/Controller/GithubController.php @@ -48,7 +48,7 @@ class GithubController extends \PHPCI\Controller $build = new Build(); $build->setProjectId($project); $build->setCommitId($payload['after']); - $build->setStatus(0); + $build->setStatus(Build::STATUS_NEW); $build->setLog(''); $build->setCreated(new \DateTime()); $build->setBranch(str_replace('refs/heads/', '', $payload['ref'])); diff --git a/PHPCI/Controller/GitlabController.php b/PHPCI/Controller/GitlabController.php index 020b6346..a466f4dd 100644 --- a/PHPCI/Controller/GitlabController.php +++ b/PHPCI/Controller/GitlabController.php @@ -42,7 +42,7 @@ class GitlabController extends \PHPCI\Controller $build = new Build(); $build->setProjectId($project); $build->setCommitId($payload['after']); - $build->setStatus(0); + $build->setStatus(Build::STATUS_NEW); $build->setLog(''); $build->setCreated(new \DateTime()); $build->setBranch(str_replace('refs/heads/', '', $payload['ref'])); diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index 1a4fc496..7c0b75e7 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -69,7 +69,7 @@ class ProjectController extends \PHPCI\Controller $build = new Build(); $build->setProjectId($projectId); $build->setCommitId('Manual'); - $build->setStatus(0); + $build->setStatus(Build::STATUS_NEW); $build->setBranch($project->getType() === 'hg' ? 'default' : 'master'); $build->setCreated(new \DateTime());