/**
  * @param \JenkinsRun $run
  * @param \Jenkins    $jenkins
  * @param             $isRunning
  * @param             $isJenkinsAvailable
  *
  * @return array
  */
 private function buildDropdownLinksJenkinsRun(JenkinsRun $run, Jenkins $jenkins, $isRunning, $isJenkinsAvailable)
 {
     $links = array();
     $urlBuild = $run->getUrlBuild($jenkins);
     if ($isRunning || $run->isRebuildable()) {
         $links[] = array('label' => 'Delay', 'title' => 'Relaunch build (delayed)', 'url' => $this->generateUrl('run_rebuild_delayed', $run));
     }
     $links[] = array('label' => 'Remove build', 'title' => 'Remove build from build branch', 'url' => $this->generateUrl('run_remove', $run));
     $isJenkinsAvailable && ($links[] = array('label' => 'Go to console log', 'title' => 'View Jenkins console log', 'url' => $urlBuild . '/console', 'options' => array('class' => 'jenkins', 'target' => '_blank')));
     $isJenkinsAvailable && ($links[] = array('label' => 'Go to test report', 'url' => $urlBuild . '/testReport', 'options' => array('class' => 'jenkins', 'target' => '_blank')));
     return $links;
 }
Пример #2
0
 /**
  * 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)
 {
     //pas de jenkins => pas de form
     if (!$this->getJenkins()->isAvailable()) {
         $this->redirect('jenkins/index');
     }
     if (is_array($buildRequest = $request->getParameter('build'))) {
         $groupRunId = isset($buildRequest['group_run_id']) ? $buildRequest['group_run_id'] : null;
     } else {
         $groupRunId = $request->getParameter('group_run_id');
     }
     $this->forward404If($groupRunId === null, 'group_run_id parameter is required');
     $jenkinsGroupRun = JenkinsGroupRunPeer::retrieveByPK($groupRunId);
     $this->forward404Unless($jenkinsGroupRun instanceof JenkinsGroupRun, sprintf('Can\'t create JenkinsGroupRun with id %s', $groupRunId));
     $defaults = array();
     if ($request->hasParameter('auto_launch')) {
         $autoLaunch = $request->getParameter('auto_launch');
         if ('on' === $autoLaunch) {
             $defaults = array('auto_launch' => true);
         }
     } else {
         $defaults = array('auto_launch' => true);
     }
     $form = new BuildForm($defaults, array('jenkins' => $this->getJenkins(), 'group_run' => $jenkinsGroupRun));
     if (sfRequest::POST === $request->getMethod()) {
         $form->bind($buildRequest);
         if ($form->isValid()) {
             $jobName = $form->getValue('job');
             $autoLaunch = 'on' === $form->getValue('auto_launch');
             $extraParameters = $form->getValue('parameters');
             $jobParameters = array();
             if (isset($extraParameters[$jobName])) {
                 $jobParameters = $extraParameters[$jobName];
             }
             //créer les builds
             $run = new JenkinsRun();
             $run->setJenkinsGroupRun($jenkinsGroupRun);
             $run->setJobName($jobName);
             $run->encodeParameters($jobParameters);
             $run->setLaunched($autoLaunch);
             $run->save();
             //launcher les builds
             if ($autoLaunch) {
                 $run->launch($this->getJenkins(), $jobParameters);
                 $run->computeJobBuildNumber($this->getJenkins(), $this->getUser());
             }
             $this->getUser()->setFlash('info', sprintf('Build [%s] has been added to build branch [%s]', $run->getJobName(), $jenkinsGroupRun->getLabel()));
             if ($request->hasParameter('add_and_continue')) {
                 $urlRedirect = sprintf('jenkins/addBuild?auto_launch=%s&group_run_id=%s', $autoLaunch ? 'on' : 'off', $jenkinsGroupRun->getId());
             } else {
                 $urlRedirect = $this->generateUrl('branch_view', $jenkinsGroupRun);
             }
             $this->redirect($urlRedirect);
         }
     }
     $this->setVar('form', $form);
     $this->setVar('group_run', array('label' => $jenkinsGroupRun->getLabel(), 'git_branch' => $jenkinsGroupRun->getGitBranch(), 'git_branch_slug' => $jenkinsGroupRun->getGitBranchSlug(), 'result' => $jenkinsGroupRun->getResult($this->getJenkins()), 'url' => $this->generateUrl('branch_view', $jenkinsGroupRun)));
 }
Пример #3
0
 /**
  * @param JenkinsRun $jenkinsRun
  * @param Jenkins    $jenkins
  */
 private function cancelJenkinsRun(JenkinsRun $jenkinsRun, Jenkins $jenkins)
 {
     if (($build = $jenkinsRun->getJenkinsBuild($jenkins)) instanceof Jenkins_Build) {
         /** @var Jenkins_Build $build */
         if (null !== ($executor = $build->getExecutor())) {
             /** @var Jenkins_Executor $executor */
             $executor->stop();
             $this->getUser()->setFlash('info', sprintf('Build [%s] has been canceled', $jenkinsRun->getJobName()));
         } else {
             $this->getUser()->setFlash('warning', sprintf('Build [%s] can\'t be canceled, because this build is not running', $jenkinsRun->getJobName()));
         }
     } elseif (null !== ($jobQueue = $jenkinsRun->getJenkinsQueue($jenkins))) {
         $jobQueue->cancel();
         $jenkinsRun->computeJobBuildNumber($jenkins, $this->getUser());
         $this->getUser()->setFlash('info', sprintf('Build [%s] has been removed from Jenkins queue.', $jenkinsRun->getJobName()));
     } else {
         $this->getUser()->setFlash('warning', sprintf('Build [%s] can\'t be canceled, because it can\'t be possible to associate it to a Jenkins Build.
       Maybe he is now in Jenkins queue.', $jenkinsRun->getJobName()));
     }
 }
 /**
  * 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)
 {
     //pas de jenkins => pas de form
     if (!$this->getJenkins()->isAvailable()) {
         $this->redirect('jenkins/index');
     }
     $default = array('sf_guard_user_id' => $this->getUser()->getUserId());
     if ($request->hasParameter('from_group_run_id')) {
         //duplication de la configuration
         $groupRun = JenkinsGroupRunPeer::retrieveByPK($request->getParameter('from_group_run_id'));
         if (null !== $groupRun) {
             $default = $groupRun->buildDefaultFormValue($this->getJenkins(), $default);
         }
     }
     if ($request->hasParameter('branch')) {
         $branch = $request->getParameter('branch');
         $default['git_branch'] = $branch;
         $default['label'] = $branch;
     }
     $form = new GroupRunForm($default, array('jenkins' => $this->getJenkins(), 'sf_guard_user_id' => $this->getUser()->getUserId()));
     if (sfRequest::POST === $request->getMethod()) {
         $form->bind($request->getParameter('group_run'));
         if ($form->isValid()) {
             $autoLaunch = 'on' === $form->getValue('auto_launch');
             //création du group run
             $runGroup = new JenkinsGroupRun();
             $runGroup->setSfGuardUserId($this->getUser()->getUserId());
             $runGroup->setDate(new DateTime());
             $runGroup->setGitBranch($form->getValue('git_branch'));
             $runGroup->setLabel($form->getValue('label'));
             $runGroup->save();
             $nbJobs = 0;
             foreach ($form->getValue('builds') as $jobName => $jobInfo) {
                 if (!$jobInfo['job_name']) {
                     continue;
                 }
                 $parameters = array();
                 if (isset($jobInfo['parameters'])) {
                     $parameters = $jobInfo['parameters'];
                 }
                 //créer les builds
                 $run = new JenkinsRun();
                 $run->setJenkinsGroupRun($runGroup);
                 $run->setJobName($jobName);
                 $run->encodeParameters($parameters);
                 $run->setLaunched($autoLaunch);
                 $run->save();
                 $nbJobs++;
                 if ($autoLaunch) {
                     //launcher les builds
                     $run->launch($this->getJenkins(), $parameters);
                     $run->computeJobBuildNumber($this->getJenkins(), $this->getUser());
                 }
             }
             if (0 === $nbJobs) {
                 $this->getUser()->setFlash('info', sprintf('Build branch [%s] has been created', $runGroup->getLabel()));
             } else {
                 $label = 1 === $nbJobs ? 'Job has ' : 'Jobs have ';
                 $this->getUser()->setFlash('info', $label . ($autoLaunch ? "been launched" : "been registered in delayed list"));
             }
             $this->redirect($this->generateUrl('branch_view', $runGroup));
         }
     }
     $views = $this->getViews($this->getJenkins());
     $defaultView = $this->getJenkins()->getPrimaryView();
     $this->setVar('form', $form);
     $this->setVar('view_by_jobs', $this->buildViewByJobs($this->getJenkins()));
     $this->setVar('views', $views);
     $this->setVar('default_active_view', null === $defaultView ? null : $defaultView->getName());
 }