Lots of clean up: Fixed remote git build to only checkout a commit if there is one, cleaned up logging to remove the logger cruft from the visible log and shortened paths within the log by removing the build directory, added a build-level exception handler to catch things like failed clones and so on.

This commit is contained in:
Dan Cryer 2014-02-25 10:16:58 +00:00
parent a1f47ddfe1
commit d935c94041
5 changed files with 32 additions and 13 deletions

View file

@ -268,8 +268,9 @@ class Builder implements LoggerAwareInterface
{
$buildId = 'project' . $this->build->getProject()->getId(
) . '-build' . $this->build->getId();
$this->ciDir = dirname(__FILE__) . '/../';
$this->ciDir = dirname(dirname(__FILE__) . '/../') . '/';
$this->buildPath = $this->ciDir . 'build/' . $buildId . '/';
$this->build->currentBuildPath = $this->buildPath;
$this->interpolator->setupInterpolationVars(
$this->build,

View file

@ -22,6 +22,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use b8\Store\Factory;
use PHPCI\Builder;
use PHPCI\BuildFactory;
use PHPCI\Model\Build;
/**
* Run console command - Runs any pending builds.
@ -68,7 +69,7 @@ class RunCommand extends Command
// For verbose mode we want to output all informational and above
// messages to the symphony output interface.
if ($input->hasOption('verbose')) {
if ($input->getOption('verbose')) {
$this->logger->pushHandler(
new OutputLogHandler($this->output, Logger::INFO)
);
@ -88,17 +89,24 @@ class RunCommand extends Command
$build = BuildFactory::getBuild($build);
// Logging relevant to this build should be stored
// against the build itself.
$buildDbLog = new BuildDBLogHandler($build, Logger::INFO);
$this->logger->pushHandler($buildDbLog);
try {
// Logging relevant to this build should be stored
// against the build itself.
$buildDbLog = new BuildDBLogHandler($build, Logger::INFO);
$this->logger->pushHandler($buildDbLog);
$builder = new Builder($build, $this->logger);
$builder->execute();
$builder = new Builder($build, $this->logger);
$builder->execute();
// After execution we no longer want to record the information
// back to this specific build so the handler should be removed.
$this->logger->popHandler($buildDbLog);
} catch (\Exception $ex) {
$build->setStatus(Build::STATUS_FAILED);
$build->setLog($build->getLog() . PHP_EOL . PHP_EOL . $ex->getMessage());
$store->save($build);
}
// After execution we no longer want to record the information
// back to this specific build so the handler should be removed.
$this->logger->popHandler($buildDbLog);
}
$this->logger->addInfo("Finished processing builds");

View file

@ -29,7 +29,10 @@ class BuildDBLogHandler extends AbstractProcessingHandler
protected function write(array $record)
{
$this->logValue .= (string)$record['formatted'];
$message = (string)$record['message'];
$message = str_replace($this->build->currentBuildPath, '/', $message);
$this->logValue .= $message . PHP_EOL;
$this->build->setLog($this->logValue);
}
}

View file

@ -26,6 +26,8 @@ class Build extends BuildBase
const STATUS_SUCCESS = 2;
const STATUS_FAILED = 3;
public $currentBuildPath = null;
/**
* Get link to commit from another source (i.e. Github)
*/

View file

@ -89,7 +89,12 @@ class RemoteGitBuild extends Build
// Use the key file to do an SSH clone:
$cmd = 'eval `ssh-agent -s` && ssh-add "%s" && git clone -b %s %s "%s" && ssh-agent -k';
$success = $builder->executeCommand($cmd, $keyFile, $this->getBranch(), $this->getCloneUrl(), $cloneTo);
$builder->executeCommand('cd "%s" && git checkout %s', $cloneTo, $this->getCommitId());
$commit = $this->getCommitId();
if (!empty($commit) && $commit != 'Manual') {
$builder->executeCommand('cd "%s" && git checkout %s', $cloneTo, $this->getCommitId());
}
// Remove the key file:
unlink($keyFile);