Added a new configuration variable, PHPCI_BUILD_ROOT_DI.

This variable allows to change where the build happens.
It defaults to PHPCI_DIR.'PHPCI/build/'.

Moved build path calculate and build removal into the Build class.

Also remove the build directory when deleting the build.

Close #834
This commit is contained in:
Adirelle 2015-02-27 10:51:18 +01:00 committed by Tobias van Beek
parent 60131ae7b6
commit 9590336c49
5 changed files with 37 additions and 26 deletions

View file

@ -215,15 +215,6 @@ class Builder implements LoggerAwareInterface
$this->pluginExecutor->executePlugins($this->config, 'failure');
$this->buildLogger->logFailure(Lang::get('build_failed'));
}
// Clean up:
$this->buildLogger->log(Lang::get('removing_build'));
$cmd = 'rm -Rf "%s"';
if (IS_WIN) {
$cmd = 'rmdir /S /Q "%s"';
}
$this->executeCommand($cmd, rtrim($this->buildPath, '/'));
} catch (\Exception $ex) {
$this->build->setStatus(Build::STATUS_FAILED);
$this->buildLogger->logFailure(Lang::get('exception') . $ex->getMessage());
@ -233,6 +224,11 @@ class Builder implements LoggerAwareInterface
// Update the build in the database, ping any external services, etc.
$this->build->sendStatusPostback();
$this->build->setFinished(new \DateTime());
// Clean up:
$this->buildLogger->log(Lang::get('removing_build'));
$this->build->removeBuildDirectory();
$this->store->save($this->build);
}
@ -287,7 +283,7 @@ class Builder implements LoggerAwareInterface
*/
protected function setupBuild()
{
$this->buildPath = PHPCI_DIR . 'PHPCI/build/' . $this->build->getId() . '/';
$this->buildPath = $this->build->getBuildPath() . '/';
$this->build->currentBuildPath = $this->buildPath;
$this->interpolator->setupInterpolationVars(

View file

@ -166,7 +166,7 @@ class RunCommand extends Command
$build->setStatus(Build::STATUS_FAILED);
$build->setFinished(new \DateTime());
$store->save($build);
$this->removeBuildDirectory($build);
$build->removeBuildDirectory();
continue;
}
@ -175,19 +175,4 @@ class RunCommand extends Command
return $rtn;
}
protected function removeBuildDirectory($build)
{
$buildPath = PHPCI_DIR . 'PHPCI/build/' . $build->getId() . '/';
if (is_dir($buildPath)) {
$cmd = 'rm -Rf "%s"';
if (IS_WIN) {
$cmd = 'rmdir /S /Q "%s"';
}
shell_exec($cmd);
}
}
}

View file

@ -217,4 +217,28 @@ class Build extends BuildBase
{
return array($builder, $file, $line, $message);
}
/**
* Return the path to run this build into.
*
* @return string
*/
public function getBuildPath()
{
return PHPCI_BUILD_ROOT_DIR . $this->getId();
}
/**
* Removes the build directory.
*/
public function removeBuildDirectory()
{
$buildPath = $this->getBuildPath();
if (!is_dir($buildPath)) {
return;
}
exec(sprintf(IS_WIN ? 'rmdir /S /Q "%s"' : 'rm -Rf "%s"', $buildPath));
}
}

View file

@ -112,6 +112,7 @@ class BuildService
*/
public function deleteBuild(Build $build)
{
$build->removeBuildDirectory();
return $this->buildStore->delete($build);
}
}

View file

@ -16,6 +16,11 @@ if (!defined('PHPCI_BIN_DIR')) {
define('PHPCI_BIN_DIR', PHPCI_DIR . 'vendor/bin/');
}
// Define PHPCI_BUILD_ROOT_DIR
if (!defined('PHPCI_BUILD_ROOT_DIR')) {
define('PHPCI_BUILD_ROOT_DIR', PHPCI_DIR . 'PHPCI/build/');
}
// Should PHPCI run the Shell plugin?
if (!defined('ENABLE_SHELL_PLUGIN')) {
define('ENABLE_SHELL_PLUGIN', false);