예제 #1
0
 /**
  * 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);
 }
예제 #2
0
 /**
  * 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);
 }
예제 #3
0
 /**
  * @param $configId
  * @param bool $setProject
  * @return Build
  */
 protected function getBuild($configId, $setProject = true)
 {
     $config = array('1' => array('status' => Build::STATUS_RUNNING, 'id' => 77, 'finishDateTime' => null, 'startedDate' => '2014-10-25 21:20:02', 'previousBuild' => null), '2' => array('status' => Build::STATUS_RUNNING, 'id' => 78, 'finishDateTime' => null, 'startedDate' => '2014-10-25 21:20:02', 'previousBuild' => 4), '3' => array('status' => Build::STATUS_SUCCESS, 'id' => 7, 'finishDateTime' => '2014-10-25 21:50:02', 'startedDate' => '2014-10-25 21:20:02', 'previousBuild' => null), '4' => array('status' => Build::STATUS_FAILED, 'id' => 13, 'finishDateTime' => '2014-10-13 13:13:13', 'previousBuild' => null), '5' => array('status' => Build::STATUS_NEW, 'id' => 1000, 'finishDateTime' => '2014-12-25 21:12:21', 'previousBuild' => 3));
     $build = new Build();
     $build->setId($config[$configId]['id']);
     $build->setBranch(self::BRANCH);
     $build->setStatus($config[$configId]['status']);
     if ($config[$configId]['finishDateTime']) {
         $build->setFinished(new \DateTime($config[$configId]['finishDateTime']));
     }
     if (!empty($config[$configId]['startedDate'])) {
         $build->setStarted(new \DateTime('2014-10-25 21:20:02'));
     }
     $project = $this->getProjectMock($config[$configId]['previousBuild'], $setProject);
     $build->setProjectObject($project);
     return $build;
 }
예제 #4
0
 /**
  * @covers PHPUnit::execute
  */
 public function testExecute_CreateDuplicateBuild()
 {
     $build = new Build();
     $build->setId(1);
     $build->setProject(101);
     $build->setCommitId('abcde');
     $build->setStatus(Build::STATUS_FAILED);
     $build->setLog('Test');
     $build->setBranch('example_branch');
     $build->setStarted(new \DateTime());
     $build->setFinished(new \DateTime());
     $build->setCommitMessage('test');
     $build->setCommitterEmail('*****@*****.**');
     $build->setExtra(json_encode(array('item1' => 1001)));
     $returnValue = $this->testedService->createDuplicateBuild($build);
     $this->assertNotEquals($build->getId(), $returnValue->getId());
     $this->assertEquals($build->getProjectId(), $returnValue->getProjectId());
     $this->assertEquals($build->getCommitId(), $returnValue->getCommitId());
     $this->assertNotEquals($build->getStatus(), $returnValue->getStatus());
     $this->assertEquals(Build::STATUS_NEW, $returnValue->getStatus());
     $this->assertNull($returnValue->getLog());
     $this->assertEquals($build->getBranch(), $returnValue->getBranch());
     $this->assertNotEquals($build->getCreated(), $returnValue->getCreated());
     $this->assertNull($returnValue->getStarted());
     $this->assertNull($returnValue->getFinished());
     $this->assertEquals('test', $returnValue->getCommitMessage());
     $this->assertEquals('*****@*****.**', $returnValue->getCommitterEmail());
     $this->assertEquals($build->getExtra('item1'), $returnValue->getExtra('item1'));
 }