/** * Send a notification mail. */ public function execute() { $addresses = $this->getEmailAddresses(); // Without some email addresses in the yml file then we // can't do anything. if (count($addresses) == 0) { return false; } $buildStatus = $this->build->isSuccessful() ? "Passing Build" : "Failing Build"; $projectName = $this->build->getProject()->getTitle(); try { $view = $this->getMailTemplate(); } catch (Exception $e) { $this->phpci->log(sprintf('Unknown mail template "%s", falling back to default.', $this->options['template']), LogLevel::WARNING); $view = $this->getDefaultMailTemplate(); } $view->build = $this->build; $view->project = $this->build->getProject(); $layout = new View('Email/layout'); $layout->build = $this->build; $layout->project = $this->build->getProject(); $layout->content = $view->render(); $body = $layout->render(); $sendFailures = $this->sendSeparateEmails($addresses, sprintf("PHPCI - %s - %s", $projectName, $buildStatus), $body); // This is a success if we've not failed to send anything. $this->phpci->log(sprintf("%d emails sent", count($addresses) - $sendFailures)); $this->phpci->log(sprintf("%d emails failed to send", $sendFailures)); return $sendFailures === 0; }
/** * Takes a generic build and returns a type-specific build model. * @param Build $base The build from which to get a more specific build type. * @return Build */ public static function getBuild(Build $base) { switch ($base->getProject()->getType()) { case 'remote': $type = 'RemoteGitBuild'; break; case 'local': $type = 'LocalBuild'; break; case 'github': $type = 'GithubBuild'; break; case 'bitbucket': $type = 'BitbucketBuild'; break; case 'gitlab': $type = 'GitlabBuild'; break; case 'hg': $type = 'MercurialBuild'; break; } $type = '\\PHPCI\\Model\\Build\\' . $type; return new $type($base->getDataArray()); }
/** * Takes a generic build and returns a type-specific build model. * @param Build $build The build from which to get a more specific build type. * @return Build */ public static function getBuild(Build $build) { $project = $build->getProject(); if (!empty($project)) { switch ($project->getType()) { case 'remote': $type = 'RemoteGitBuild'; break; case 'local': $type = 'LocalBuild'; break; case 'github': $type = 'GithubBuild'; break; case 'bitbucket': $type = 'BitbucketBuild'; break; case 'gitlab': $type = 'GitlabBuild'; break; case 'hg': $type = 'MercurialBuild'; break; case 'svn': $type = 'SubversionBuild'; break; default: return $build; } $class = '\\PHPCI\\Model\\Build\\' . $type; $build = new $class($build->getDataArray()); } return $build; }
/** * 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); }
/** * Send a notification mail. */ public function execute() { $addresses = $this->getEmailAddresses(); // Without some email addresses in the yml file then we // can't do anything. if (count($addresses) == 0) { return false; } $buildStatus = $this->build->isSuccessful() ? "Passing Build" : "Failing Build"; $projectName = $this->build->getProject()->getTitle(); $mailTemplate = $this->build->isSuccessful() ? 'Email/success' : 'Email/failed'; $view = new View($mailTemplate); $view->build = $this->build; $view->project = $this->build->getProject(); $body = $view->render(); $sendFailures = $this->sendSeparateEmails($addresses, sprintf("PHPCI - %s - %s", $projectName, $buildStatus), $body); // This is a success if we've not failed to send anything. $this->phpci->log(sprintf("%d emails sent", count($addresses) - $sendFailures)); $this->phpci->log(sprintf("%d emails failed to send", $sendFailures)); return $sendFailures === 0; }
/** * 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; }
/** * @return string The title of the project being built. */ public function getBuildProjectTitle() { return $this->build->getProject()->getTitle(); }