/** * Standard Constructor * * $options[<branch>]['env'] Filepath to source environment file. * $options[<branch>]['path'] Filepath to destination environment file. * * @param Builder $phpci * @param Build $build * @param array $options * */ public function __construct(Builder $phpci, Build $build, array $options = []) { $this->phpci = $phpci; $this->build = $build; $this->branch = $this->build->getBranch(); $this->envFilepath = $this->loadEnvPath($options); $this->envFilename = $this->loadFilename($options); }
/** * Standard Constructor * * $options[<branch>]['url'] Trigger URL. * $options[<branch>]['method'] Method to call the trigger url with. Default: GET * * @param Builder $phpci * @param Build $build * @param array $options * * @throws \Exception */ public function __construct(Builder $phpci, Build $build, array $options = []) { $this->phpci = $phpci; $this->build = $build; $this->branch = $this->build->getBranch(); $this->deployUrl = $this->getDeploymentUrl($options); $this->requestMethod = $this->getDeploymentMethod($options); }
/** * Deployer constructor. * @param Builder $phpci * @param Build $build * @param array $options */ public function __construct(Builder $phpci, Build $build, array $options = []) { $this->phpci = $phpci; $this->build = $build; if (!empty($options)) { $this->options = $options; } $this->currentBranch = $this->build->getBranch(); }
/** * Run the active build. */ public function execute() { // Update the build in the database, ping any external services. $this->build->setStatus(Build::STATUS_RUNNING); $this->build->setStarted(new \DateTime()); $this->store->save($this->build); $this->build->sendStatusPostback(); $success = true; $previous_build = $this->build->getProject()->getPreviousBuild($this->build->getBranch()); $previous_state = Build::STATUS_NEW; if ($previous_build) { $previous_state = $previous_build->getStatus(); } try { // Set up the build: $this->setupBuild(); // Run the core plugin stages: foreach (array('setup', 'test') as $stage) { $success &= $this->pluginExecutor->executePlugins($this->config, $stage); } // Set the status so this can be used by complete, success and failure // stages. if ($success) { $this->build->setStatus(Build::STATUS_SUCCESS); } else { $this->build->setStatus(Build::STATUS_FAILED); } if ($success) { $this->pluginExecutor->executePlugins($this->config, 'success'); if ($previous_state == Build::STATUS_FAILED) { $this->pluginExecutor->executePlugins($this->config, 'fixed'); } $this->buildLogger->logSuccess(Lang::get('build_success')); } else { $this->pluginExecutor->executePlugins($this->config, 'failure'); if ($previous_state == Build::STATUS_SUCCESS || $previous_state == Build::STATUS_NEW) { $this->pluginExecutor->executePlugins($this->config, 'broken'); } $this->buildLogger->logFailure(Lang::get('build_failed')); } } catch (\Exception $ex) { $this->build->setStatus(Build::STATUS_FAILED); $this->buildLogger->logFailure(Lang::get('exception') . $ex->getMessage()); } finally { // Complete stage plugins are always run $this->pluginExecutor->executePlugins($this->config, 'complete'); } // 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); }
/** * Sets the variables that will be used for interpolation. * @param Build $build * @param string $buildPath * @param string $phpCiUrl */ public function setupInterpolationVars(Build $build, $buildPath, $phpCiUrl) { $this->interpolation_vars = array(); $this->interpolation_vars['%PHPCI%'] = 1; $this->interpolation_vars['%COMMIT%'] = $build->getCommitId(); $this->interpolation_vars['%SHORT_COMMIT%'] = substr($build->getCommitId(), 0, 7); $this->interpolation_vars['%COMMIT_EMAIL%'] = $build->getCommitterEmail(); $this->interpolation_vars['%COMMIT_MESSAGE%'] = $build->getCommitMessage(); $this->interpolation_vars['%COMMIT_URI%'] = $build->getCommitLink(); $this->interpolation_vars['%BRANCH%'] = $build->getBranch(); $this->interpolation_vars['%BRANCH_URI%'] = $build->getBranchLink(); $this->interpolation_vars['%PROJECT%'] = $build->getProjectId(); $this->interpolation_vars['%BUILD%'] = $build->getId(); $this->interpolation_vars['%PROJECT_TITLE%'] = $build->getProjectTitle(); $this->interpolation_vars['%PROJECT_URI%'] = $phpCiUrl . "project/view/" . $build->getProjectId(); $this->interpolation_vars['%BUILD_PATH%'] = $buildPath; $this->interpolation_vars['%BUILD_URI%'] = $phpCiUrl . "build/view/" . $build->getId(); $this->interpolation_vars['%PHPCI_COMMIT%'] = $this->interpolation_vars['%COMMIT%']; $this->interpolation_vars['%PHPCI_SHORT_COMMIT%'] = $this->interpolation_vars['%SHORT_COMMIT%']; $this->interpolation_vars['%PHPCI_COMMIT_MESSAGE%'] = $this->interpolation_vars['%COMMIT_MESSAGE%']; $this->interpolation_vars['%PHPCI_COMMIT_EMAIL%'] = $this->interpolation_vars['%COMMIT_EMAIL%']; $this->interpolation_vars['%PHPCI_COMMIT_URI%'] = $this->interpolation_vars['%COMMIT_URI%']; $this->interpolation_vars['%PHPCI_PROJECT%'] = $this->interpolation_vars['%PROJECT%']; $this->interpolation_vars['%PHPCI_BUILD%'] = $this->interpolation_vars['%BUILD%']; $this->interpolation_vars['%PHPCI_PROJECT_TITLE%'] = $this->interpolation_vars['%PROJECT_TITLE%']; $this->interpolation_vars['%PHPCI_PROJECT_URI%'] = $this->interpolation_vars['%PROJECT_URI%']; $this->interpolation_vars['%PHPCI_BUILD_PATH%'] = $this->interpolation_vars['%BUILD_PATH%']; $this->interpolation_vars['%PHPCI_BUILD_URI%'] = $this->interpolation_vars['%BUILD_URI%']; putenv('PHPCI=1'); putenv('PHPCI_COMMIT=' . $this->interpolation_vars['%COMMIT%']); putenv('PHPCI_SHORT_COMMIT=' . $this->interpolation_vars['%SHORT_COMMIT%']); putenv('PHPCI_COMMIT_MESSAGE=' . $this->interpolation_vars['%COMMIT_MESSAGE%']); putenv('PHPCI_COMMIT_EMAIL=' . $this->interpolation_vars['%COMMIT_EMAIL%']); putenv('PHPCI_COMMIT_URI=' . $this->interpolation_vars['%COMMIT_URI%']); putenv('PHPCI_PROJECT=' . $this->interpolation_vars['%PROJECT%']); putenv('PHPCI_BUILD=' . $this->interpolation_vars['%BUILD%']); putenv('PHPCI_PROJECT_TITLE=' . $this->interpolation_vars['%PROJECT_TITLE%']); putenv('PHPCI_BUILD_PATH=' . $this->interpolation_vars['%BUILD_PATH%']); putenv('PHPCI_BUILD_URI=' . $this->interpolation_vars['%BUILD_URI%']); }