/** * Allows the UI to poll for the latest running and pending builds. */ public function latest() { $rtn = array('pending' => $this->formatBuilds($this->buildStore->getByStatus(Build::STATUS_NEW)), 'running' => $this->formatBuilds($this->buildStore->getByStatus(Build::STATUS_RUNNING))); $response = new JsonResponse(); $response->setContent($rtn); return $response; }
/** * Allows the UI to poll for the latest running and pending builds. */ public function latest() { $rtn = array('pending' => $this->formatBuilds($this->buildStore->getByStatus(Build::STATUS_NEW)), 'running' => $this->formatBuilds($this->buildStore->getByStatus(Build::STATUS_RUNNING))); if ($this->request->isAjax()) { die(json_encode($rtn)); } }
protected function createBuild($projectId, $commitId, $branch, $committer, $commitMessage, $extra = null) { // Check if a build already exists for this commit ID: $builds = $this->buildStore->getByProjectAndCommit($projectId, $commitId); if ($builds['count']) { return true; } // If not, create a new build job for it: $build = new Build(); $build->setProjectId($projectId); $build->setCommitId($commitId); $build->setStatus(Build::STATUS_NEW); $build->setLog(''); $build->setCreated(new \DateTime()); $build->setBranch($branch); $build->setCommitterEmail($committer); $build->setCommitMessage($commitMessage); if (!is_null($extra)) { $build->setExtra(json_encode($extra)); } $build = BuildFactory::getBuild($this->buildStore->save($build)); // Send a status postback if the build type provides one: $build->sendStatusPostback(); return true; }
/** * Get latest builds and render as a table. */ protected function getLatestBuildsHtml() { $builds = $this->buildStore->getWhere(array(), 5, 0, array(), array('id' => 'DESC')); $view = new b8\View('BuildsTable'); foreach ($builds['items'] as &$build) { $build = BuildFactory::getBuild($build); } $view->builds = $builds['items']; return $view->render(); }
/** * 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); }
/** * AJAX call to get build meta: */ public function meta($buildId) { $build = BuildFactory::getBuildById($buildId); $key = $this->getParam('key', null); $numBuilds = $this->getParam('num_builds', 1); $data = null; if ($key && $build) { $data = $this->buildStore->getMeta($key, $build->getProjectId(), $buildId, $numBuilds); } die(json_encode($data)); }
/** * Wrapper for creating a new build. * * @param Project $project * @param string $commitId * @param string $branch * @param string $committer * @param string $commitMessage * @param array $extra * * @return array * * @throws Exception */ protected function createBuild(Project $project, $commitId, $branch, $committer, $commitMessage, array $extra = null) { // Check if a build already exists for this commit ID: $builds = $this->buildStore->getByProjectAndCommit($project->getId(), $commitId); if ($builds['count']) { return array('status' => 'ignored', 'message' => sprintf('Duplicate of build #%d', $builds['items'][0]->getId())); } // If not, create a new build job for it: $build = $this->buildService->createBuild($project, $commitId, $branch, $committer, $commitMessage, $extra); return array('status' => 'ok', 'buildID' => $build->getID()); }
/** * Render latest builds for project as HTML table. */ protected function getLatestBuildsHtml($projectId, $start = 0) { $criteria = array('project_id' => $projectId); $order = array('id' => 'DESC'); $builds = $this->buildStore->getWhere($criteria, 10, $start, array(), $order); $view = new b8\View('BuildsTable'); foreach ($builds['items'] as &$build) { $build = BuildFactory::getBuild($build); } $view->builds = $builds['items']; return array($view->render(), $builds['count']); }
/** * Delete a build. */ public function delete($buildId) { if (empty($_SESSION['user']) || !$_SESSION['user']->getIsAdmin()) { throw new \Exception('You do not have permission to do that.'); } $build = BuildFactory::getBuildById($buildId); if (empty($build)) { throw new NotFoundException('Build with ID: ' . $buildId . ' does not exist.'); } $this->buildStore->delete($build); header('Location: ' . PHPCI_URL . 'project/view/' . $build->getProjectId()); exit; }
/** * 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; 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); } // Complete stage plugins are always run $this->pluginExecutor->executePlugins($this->config, 'complete'); if ($success) { $this->pluginExecutor->executePlugins($this->config, 'success'); $this->buildLogger->logSuccess(Lang::get('build_success')); } else { $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, $this->buildPath); } catch (\Exception $ex) { $this->build->setStatus(Build::STATUS_FAILED); $this->buildLogger->logFailure(Lang::get('exception') . $ex->getMessage()); } // Update the build in the database, ping any external services, etc. $this->build->sendStatusPostback(); $this->build->setFinished(new \DateTime()); $this->store->save($this->build); }
protected function createBuild($projectId, $commitId, $branch, $committer, $commitMessage, $extra = null) { // Check if a build already exists for this commit ID: $builds = $this->buildStore->getByProjectAndCommit($projectId, $commitId); if ($builds['count']) { return true; } $project = $this->projectStore->getById($projectId); if (empty($project)) { throw new \Exception('Project does not exist:' . $projectId); } // If not, create a new build job for it: $build = $this->buildService->createBuild($project, $commitId, $branch, $committer, $commitMessage, $extra); $build = BuildFactory::getBuild($build); // Send a status postback if the build type provides one: $build->sendStatusPostback(); return true; }
/** * Sets the summary data of the current build. * * @param array summary */ private function setBuildSummary($summary) { $build = $this->pluginFactory->getResourceFor('PHPCI\\Model\\Build'); $this->store->setMeta($build->getProjectId(), $build->getId(), 'plugin-summary', json_encode($summary)); }
/** * Delete a given build. * @param Build $build * @return bool */ public function deleteBuild(Build $build) { $build->removeBuildDirectory(); return $this->buildStore->delete($build); }
/** * Delete a given build. * @param Build $build * @return bool */ public function deleteBuild(Build $build) { return $this->buildStore->delete($build); }