Merge pull request #233 from meadsteve/build-status-fix

Refactor how the plugin stages are called
This commit is contained in:
Dan Cryer 2013-12-09 08:52:41 -08:00
commit 2cc554d9aa
8 changed files with 31 additions and 29 deletions

View file

@ -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:

View file

@ -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());

View file

@ -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);

View file

@ -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());

View file

@ -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) {

View file

@ -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']));

View file

@ -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']));

View file

@ -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());