/** * * @return bool|null * @throws \Exception */ public function execute() { // No configuration found if (empty($this->options)) { throw new \Exception('No deployer configuration found, are you sure you added configuration?'); } /** @var array $branchConfiguration */ $branchConfiguration = $this->_getConfigurationForCurrentBranch(); // Current Branch does not exist in the configuration, silently ignore if ($branchConfiguration === null) { return null; } // Copy the deploy.php if set if (isset($this->options['deployFile'])) { if ($this->phpci->executeCommand('cp ' . $this->options['deployFile'] . ' ' . $this->build->currentBuildPath . '/deploy.php')) { $this->phpci->log('Copied the deploy file successfully.'); } } // Validate the yaml configuration and if correct: deploy if ($this->_validateDeployerOptions($branchConfiguration)) { // Lets deploy... $env = 'STAGE=' . $branchConfiguration['stage'] . ' '; $env .= 'SERVER=' . $branchConfiguration['server'] . ' '; $env .= 'USER='******'user'] . ' '; $env .= 'DEPLOY_PATH=' . $branchConfiguration['deploy_path'] . ' '; $env .= 'BRANCH=' . $branchConfiguration['branch'] . ' '; $env .= 'REPOSITORY=' . $branchConfiguration['repository'] . ' '; $env .= 'SHARED_DIRS=' . implode(',', $branchConfiguration['shared_dirs']) . ' '; $env .= 'WRITABLE_DIRS=' . implode(',', $branchConfiguration['writable_dirs']) . ' '; $env .= 'BUILD=' . $this->build->getId() . ' '; try { $this->phpci->executeCommand('cd ' . $this->build->currentBuildPath); $command = $env . 'dep deploy ' . $branchConfiguration['stage']; if ($this->phpci->executeCommand($command)) { $success = true; } else { $this->phpci->logFailure('Something went wrong at the deployer part.' . PHP_EOL . 'The following command was used:' . PHP_EOL . $command); $success = false; } } catch (\Exception $e) { $this->phpci->logFailure('Something went wrong at the deployer part.', $e); $success = false; } } else { $success = false; } return $success; }
/** * 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%']); }
/** * 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['%PROJECT%'] = $build->getProjectId(); $this->interpolation_vars['%BUILD%'] = $build->getId(); $this->interpolation_vars['%PROJECT_TITLE%'] = $build->getProjectTitle(); $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_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_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_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%']); }
/** * Set up a working copy of the project for building. */ protected function setupBuild() { $this->buildPath = PHPCI_DIR . 'PHPCI/build/' . $this->build->getId() . '/'; $this->build->currentBuildPath = $this->buildPath; $this->interpolator->setupInterpolationVars($this->build, $this->buildPath, PHPCI_URL); // Create a working copy of the project: if (!$this->build->createWorkingCopy($this, $this->buildPath)) { throw new \Exception(Lang::get('could_not_create_working')); } // Does the project's phpci.yml request verbose mode? if (!isset($this->config['build_settings']['verbose']) || !$this->config['build_settings']['verbose']) { $this->verbose = false; } // Does the project have any paths it wants plugins to ignore? if (isset($this->config['build_settings']['ignore'])) { $this->ignore = $this->config['build_settings']['ignore']; } $this->buildLogger->logSuccess(Lang::get('working_copy_created', $this->buildPath)); return true; }
/** * Set up a working copy of the project for building. */ protected function setupBuild() { $buildId = 'project' . $this->build->getProject()->getId() . '-build' . $this->build->getId(); $this->ciDir = dirname(dirname(__FILE__) . '/../') . '/'; $this->buildPath = $this->ciDir . 'build/' . $buildId . '/'; $this->build->currentBuildPath = $this->buildPath; $this->interpolator->setupInterpolationVars($this->build, $this->buildPath, PHPCI_URL); // Create a working copy of the project: if (!$this->build->createWorkingCopy($this, $this->buildPath)) { throw new \Exception('Could not create a working copy.'); } // Does the project's phpci.yml request verbose mode? if (!isset($this->config['build_settings']['verbose']) || !$this->config['build_settings']['verbose']) { $this->verbose = false; } // Does the project have any paths it wants plugins to ignore? if (isset($this->config['build_settings']['ignore'])) { $this->ignore = $this->config['build_settings']['ignore']; } $this->buildLogger->logSuccess('Working copy created: ' . $this->buildPath); return true; }
/** * Get build data from database and json encode it: */ protected function getBuildData(Build $build) { $data = array(); $data['status'] = (int) $build->getStatus(); $data['log'] = $this->cleanLog($build->getLog()); $data['created'] = !is_null($build->getCreated()) ? $build->getCreated()->format('Y-m-d H:i:s') : null; $data['started'] = !is_null($build->getStarted()) ? $build->getStarted()->format('Y-m-d H:i:s') : null; $data['finished'] = !is_null($build->getFinished()) ? $build->getFinished()->format('Y-m-d H:i:s') : null; $data['duration'] = $build->getDuration(); /** @var \PHPCI\Store\BuildErrorStore $errorStore */ $errorStore = b8\Store\Factory::getStore('BuildError'); $errors = $errorStore->getErrorsForBuild($build->getId(), $this->getParam('since', null)); $errorView = new b8\View('Build/errors'); $errorView->build = $build; $errorView->errors = $errors; $data['errors'] = $errorStore->getErrorTotalForBuild($build->getId()); $data['error_html'] = $errorView->render(); $data['since'] = (new \DateTime())->format('Y-m-d H:i:s'); return $data; }
/** * Set Build - Accepts a Build model. * * @param $value \PHPCI\Model\Build */ public function setBuildObject(\PHPCI\Model\Build $value) { return $this->setBuildId($value->getId()); }
/** * Takes a build and puts it into the queue to be run (if using a queue) * @param Build $build */ public function addBuildToQueue(Build $build) { $buildId = $build->getId(); if (empty($buildId)) { return; } $config = Config::getInstance(); $settings = $config->get('phpci.worker', []); if (!empty($settings['host']) && !empty($settings['queue'])) { $jobData = array('type' => 'phpci.build', 'build_id' => $build->getId()); if ($config->get('using_custom_file')) { $jobData['config'] = $config->getArray(); } $pheanstalk = new Pheanstalk($settings['host']); $pheanstalk->useTube($settings['queue']); $pheanstalk->put(json_encode($jobData), PheanstalkInterface::DEFAULT_PRIORITY, PheanstalkInterface::DEFAULT_DELAY, $config->get('phpci.worker.job_timeout', 600)); } }
private function generateDestDir(Build $build) { $destDir = PHPCI_BUILD_ROOT_DIR . 'public/reports/' . $build->getProjectId() . '/' . $build->getId(); return $destDir; }