/**
  * Verify and fill number revision from jenkins server
  * for JenkinsRun which doesn't have revision number
  *
  * @static
  *
  * @param Jenkins       $jenkins
  * @param int           $userId
  * @param Criteria|null $criteria
  * 
  * @return void
  */
 public static function fillEmptyJobBuildNumber(Jenkins $jenkins, $userId, Criteria $criteria = null)
 {
     if (null === $criteria) {
         $criteria = new Criteria();
     }
     $criteria->addJoin(JenkinsRunPeer::JENKINS_GROUP_RUN_ID, JenkinsGroupRunPeer::ID, Criteria::JOIN);
     $criteria->add(JenkinsRunPeer::JOB_BUILD_NUMBER, null, Criteria::ISNULL);
     $criteria->add(JenkinsRunPeer::LAUNCHED, 1, Criteria::EQUAL);
     $criteria->add(JenkinsGroupRunPeer::SF_GUARD_USER_ID, $userId, Criteria::EQUAL);
     $emptyRunsByJobName = array();
     foreach (JenkinsRunPeer::doSelect($criteria) as $run) {
         /** @var JenkinsRun $run */
         if ($run->isInJenkinsQueue($jenkins)) {
             continue;
         }
         $emptyRunsByJobName[$run->getJobName()][$run->getId()] = $run;
     }
     foreach ($emptyRunsByJobName as $jobName => $runs) {
         /** @var Jenkins_Job $jenkinsJob  */
         $jenkinsJob = $jenkins->getJob($jobName);
         foreach ($runs as $run) {
             /** @var JenkinsRun $run  */
             /** @var Jenkins_Build $build  */
             foreach ($jenkinsJob->getBuilds() as $build) {
                 if ($run->isRelatedToJenkinsBuild($build)) {
                     $run->setJobBuildNumber($build->getNumber());
                     $run->save();
                     break;
                 }
             }
         }
     }
 }
 /**
  * 
  */
 public function preExecute()
 {
     parent::preExecute();
     $userId = $this->getUser()->getUserId();
     $jenkins = $this->getJenkins();
     if ($jenkins->isAvailable()) {
         JenkinsRunPeer::fillEmptyJobBuildNumber($jenkins, $userId);
     }
 }
 /**
  * @param sfRequest $request The current sfRequest object
  *
  * @return mixed     A string containing the view name associated with this action
  */
 function execute($request)
 {
     $runs = JenkinsRunPeer::getDelayed($this->getUser());
     $form = new DelayedRunForm(array(), array('runs' => $runs));
     $jenkins = $this->getJenkins();
     if (sfRequest::POST === $request->getMethod()) {
         $form->bind($request->getParameter('delayed_run'));
         if ($form->isValid()) {
             $messages = array();
             foreach ($form->getValue('runs') as $id => $datas) {
                 $run = JenkinsRunPeer::retrieveByPK($id);
                 if ('on' !== $datas['launch_job']) {
                     $run->setLaunchDelayed(null);
                     $run->save();
                     continue;
                 }
                 $launchAt = null;
                 if (strlen($datas['scheduled_at']) > 0) {
                     $launchAt = strtotime($datas['scheduled_at']);
                 }
                 if (null === $launchAt) {
                     $run->launchDelayed($this->getJenkins());
                     $messages[] = sprintf('The job [%s] in build branch has been launched', $run->getJobName(), $run->getGitBranch());
                 } else {
                     $run->setLaunchDelayed($launchAt);
                     $run->save();
                     $messages[] = sprintf('The job [%s] in build %s branch will be launched at %s ', $run->getJobName(), $run->getGitBranch(), $run->getLaunchDelayed('Y-m-d H:i'));
                 }
             }
             $this->getUser()->setFlash('info', $messages);
             $this->redirect('jenkins/index');
         }
     }
     $delayedRuns = array();
     $durationFormatter = new durationFormatter();
     foreach ($runs as $run) {
         $groupRun = $run->getJenkinsGroupRun();
         $parameters = $run->getParameters();
         $build = $run->getJenkinsJob($jenkins)->getLastSuccessfulBuild($jenkins);
         $lastDuration = 0;
         if (null !== $build) {
             $lastDuration = $build->getDuration();
         }
         $delayedRuns[$run->getId()] = array('group_run_label' => $groupRun->getLabel(), 'group_run_url' => $this->generateUrl('branch_view', $groupRun), 'group_run_result' => $groupRun->getResult($jenkins), 'last_duration' => $lastDuration, 'parameters' => null === $parameters ? $parameters : json_decode($run->getParameters(), true));
     }
     $this->setVar('form', $form);
     $this->setVar('delayed_runs', $delayedRuns);
     $this->setVar('duration_formatter', $durationFormatter);
 }
 /**
  * Execute any application/business logic for this component.
  *
  * @param sfRequest $request The current sfRequest object
  *
  * @return mixed     A string containing the view name associated with this action
  */
 function execute($request)
 {
     $jenkinsFactory = new Jenkins_Factory();
     $availableJenkinsUrl = null;
     if ($this->getUser()->isAuthenticated()) {
         $jenkins = $jenkinsFactory->build($this->getUser()->getJenkinsUrl());
         $availableJenkinsUrl = $jenkins->isAvailable() ? $jenkins->getUrl() : null;
     }
     $nbJobDelayed = count(JenkinsRunPeer::getDelayed($this->getUser()));
     $menus = array('Dashboard' => array('url' => 'jenkins/index'), 'Create a build branch' => array('url' => 'jenkins/createGroupRun'), $nbJobDelayed => array('url' => 'jenkins/delayed', 'title' => 'See delayed list', 'class' => 'btn btn-primary btn-delayed', 'dropdown_class' => 'btn btn-primary btn-delayed-caret', 'dropdowns' => array('Launch all delayed jobs' => array('url' => 'jenkins/launchAllDelayed', 'title' => sprintf('Launch all delayed jobs (%s)', $nbJobDelayed)))));
     $activeLink = sprintf('%s/%s', $this->getContext()->getActionStack()->getFirstEntry()->getModuleName(), $this->getContext()->getActionStack()->getFirstEntry()->getActionName());
     $this->setVar('menus', $menus);
     $this->setVar('activeLink', $activeLink);
     $this->setVar('user', $this->getUser());
     $this->setVar('available_jenkins_url', $availableJenkinsUrl);
 }
 /**
  * @return void
  */
 public function preExecute()
 {
     if (null === $this->getJenkinsUrl()) {
         $this->getUser()->setFlash('error', "There is no url for your Jenkins");
         $this->redirect('user/configure');
     }
     $jenkinsFactory = new Jenkins_Factory();
     $jenkins = $jenkinsFactory->build($this->getJenkinsUrl());
     $this->setJenkins($jenkins);
     //à chaque hit on met à jour
     if ($jenkins->isAvailable()) {
         JenkinsRunPeer::fillEmptyJobBuildNumber($jenkins, $this->getUser()->getUserId());
     } else {
         $this->getUser()->setFlash('error', 'Jenkins is not started, or your configuration is incorrect.');
     }
     $this->setVar('jenkins', $jenkins);
 }
 /**
  * @param sfWebRequest $request
  *
  */
 public function execute($request)
 {
     $branchName = $request->getParameter('git_branch_slug');
     $userId = $this->getUser()->getUserId();
     $groupRun = JenkinsGroupRunPeer::retrieveBySfGuardUserIdAndGitBranchSlug($userId, $branchName);
     $this->forward404If(null === $groupRun, sprintf('Can\'t retrieve JenkinsGroupRun with branch name %s and user id %s', $branchName, $userId));
     $delayed = $request->getParameter('delayed') == 1;
     $onlyUnstabled = $request->getParameter('unstabled') == 1;
     $groupRun->rebuild($this->getJenkins(), $delayed, $onlyUnstabled);
     JenkinsRunPeer::fillEmptyJobBuildNumber($this->getJenkins(), $this->getUser()->getUserId());
     $message = sprintf('The build [%s] has been relaunched', $groupRun->getLabel());
     if ($delayed) {
         $message = sprintf('The jobs of build [%s] have been added to the delayed list', $groupRun->getLabel());
     } elseif ($onlyUnstabled) {
         $message = sprintf('All the jobs of build [%s] have been added to the delayed list', $groupRun->getLabel());
     }
     $this->getUser()->setFlash('info', $message);
     $this->redirect($this->generateUrl('branch_view', $groupRun));
 }
 /**
  * @param sfRequest $request The current sfRequest object
  *
  * @return mixed     A string containing the view name associated with this action
  */
 function execute($request)
 {
     $numDelayedJobs = 0;
     $runs = JenkinsRunPeer::getDelayed($this->getUser());
     foreach ($runs as $run) {
         $run->launchDelayed($this->getJenkins());
         $run->computeJobBuildNumber($this->getJenkins(), $this->getUser());
         $numDelayedJobs++;
     }
     if ($numDelayedJobs > 1) {
         $this->getUser()->setFlash('info', sprintf('[%d] delayed jobs have been launched', $numDelayedJobs));
     } else {
         if ($numDelayedJobs == 1) {
             $this->getUser()->setFlash('info', '[1] delayed job has been launched');
         } else {
             $this->getUser()->setFlash('info', 'There was no delayed job to launch');
         }
     }
     $this->redirect('@homepage');
 }
 /**
  * @param sfRequest $request The current sfRequest object
  *
  * @return mixed|void A string containing the view name associated with this action|void
  * @throws Exception
  */
 function execute($request)
 {
     $jenkins = $this->getJenkins();
     if ($request->hasParameter('group_run_id')) {
         $jenkinsGroupRun = JenkinsGroupRunPeer::retrieveByPK($request->getParameter('group_run_id'));
         $this->forward404Unless($jenkinsGroupRun instanceof JenkinsGroupRun, sprintf('can\'t create JenkinsGroupRun with id %s', $request->getParameter('group_run_id')));
         $jenkinsRuns = $jenkinsGroupRun->getJenkinsRuns();
         foreach ($jenkinsRuns as $jenkinsRun) {
             $this->cancelJenkinsRun($jenkinsRun, $jenkins);
         }
         $this->getUser()->setFlash('info', sprintf('All builds of group [%s] have been canceled', $jenkinsGroupRun->getLabel()));
         $this->redirect($this->generateUrl('branch_view', $jenkinsGroupRun));
     } elseif ($request->hasParameter('run_id')) {
         $jenkinsRun = JenkinsRunPeer::retrieveByPK($request->getParameter('run_id'));
         $this->forward404Unless($jenkinsRun instanceof JenkinsRun, sprintf('can\'t create JenkinsRun with id %s', $request->getParameter('run_id')));
         $this->cancelJenkinsRun($jenkinsRun, $jenkins);
         $this->redirect($this->generateUrl('branch_view', $jenkinsRun->getJenkinsGroupRun()));
     } else {
         throw new Exception('run_id or group_run_id parameter is required');
     }
 }
 /**
  * @param jenkinsKhanUser $user
  *
  * @return JenkinsRun[]
  */
 public function getDelayedRuns(jenkinsKhanUser $user)
 {
     return JenkinsRunPeer::getDelayed($user);
 }
Exemple #10
0
 public function computeJobBuildNumber(Jenkins $jenkins, myUser $user)
 {
     if (null !== $this->getJobBuildNumber()) {
         return;
     }
     $criteria = new Criteria();
     $criteria->add(JenkinsRunPeer::ID, $this->getId());
     JenkinsRunPeer::fillEmptyJobBuildNumber($jenkins, $user->getUsername(), $criteria);
 }