/** * 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))); }
/** * * @param sfRequest $request The current sfRequest object * * @return mixed A string containing the view name associated with this action */ function execute($request) { $this->forward404Unless($request->hasParameter('id'), 'id parameter is required'); $jenkinsGroupRun = JenkinsGroupRunPeer::retrieveByPK($request->getParameter('id')); $this->forward404Unless($jenkinsGroupRun instanceof JenkinsGroupRun, sprintf('Can\'t create JenkinsGroupRun with id %s', $request->getParameter('id'))); //suppression du group run (et, en cascade, des runs) $jenkinsGroupRun->delete(null); $this->getUser()->setFlash('info', sprintf('Build branch [%s] has been deleted', $jenkinsGroupRun->getLabel())); $this->redirect('jenkins/index'); }
/** * @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 sfWebRequest $request */ public function execute($request) { /** @var Jenkins $jenkins */ $groupRunId = $this->getVar('group_run_id'); $jenkins = $this->getVar('jenkins'); $currentGroup = JenkinsGroupRunPeer::retrieveByPK($groupRunId); if (null === $currentGroup) { return sfView::NONE; } $runs = $currentGroup->getJenkinsRuns(); $dataRuns = array(); $isJenkinsAvailable = $jenkins->isAvailable(); foreach ($runs as $run) { $isCancelable = false; $progress = null; $remaining = null; $isRunning = false; $urlBuild = $run->getUrlBuild($jenkins); if (!$isJenkinsAvailable) { $isCancelable = false; } elseif (($build = $run->getJenkinsBuild($jenkins)) instanceof Jenkins_Build) { /** @var Jenkins_Build $build */ $isCancelable = $isRunning = $build->isRunning(); $progress = $build->getProgress(); $remaining = $build->getRemainingExecutionTime(); } elseif ($run->isInJenkinsQueue($jenkins)) { $isCancelable = true; } /** @var JenkinsRun $run */ $dataRuns[$run->getId()] = array('job_name' => $run->getJobName(), 'start_time' => $run->getStartTime($jenkins), 'duration' => $run->getDuration($jenkins), 'scheduled_launch' => $run->getLaunchDelayed(), 'result' => $run->getJenkinsResult($jenkins), 'parameters' => $run->getLaunched() && $isRunning ? $run->getJenkinsBuildCleanedParameter($jenkins) : $run->decodeParameters(), 'is_running' => $isRunning, 'progress' => -1 === $progress ? null : $progress, 'remaining_time' => $remaining, 'is_cancelable' => $isCancelable, 'url' => $urlBuild, 'url_console_log' => $urlBuild . '/console', 'url_rebuild' => $this->generateUrl('run_rebuild', $run), 'dropdown_links' => $this->buildDropdownLinksJenkinsRun($run, $jenkins, $isRunning, $isJenkinsAvailable), 'title_url_rebuild' => $isRunning ? "Cancel current build and relaunch" : (!$run->isRebuildable() ? "Launch build immediately" : "Relaunch build")); } $currentGroupInfos = array('id' => $currentGroup->getId(), 'git_branch' => $currentGroup->getGitBranch(), 'url_add_build' => $isJenkinsAvailable ? 'jenkins/addBuild?group_run_id=' . $currentGroup->getId() : null, 'dropdown_links' => $this->buildDropdownCurrentGroup($currentGroup, $isJenkinsAvailable)); $this->setVar('runs', $dataRuns); $this->setVar('current_group_run', $currentGroupInfos); $this->setVar('duration_formatter', new 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) { //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()); }
/** * @return string */ public function getGitBranch() { //why not using the dedicated methods ? //if JenkinsRun::getJenkinsGroupRun is used //it will probably load the JenkinsGroupRun //and store the JenkinsRun has the only in the JenkinsGroupRun //and later, when the GroupRun is used, //the collection of run is initialized but uncomplete //and it'll display a GroupRun with this only only Ru return JenkinsGroupRunPeer::retrieveByPK($this->getJenkinsGroupRunId())->getGitBranch(); }
/** * @param sfRequest $request The current sfRequest object * @return mixed A string containing the view name associated with this action */ function execute($request) { $userId = $this->getUser()->getUserId(); $jenkins = $this->getJenkins(); $sortParams = explode('_', $request->getParameter('sort')); $sortType = 'none'; $sortDirection = ''; if (count($sortParams) == 1) { $sortType = strlen($sortParams[0]) ? $sortParams[0] : 'none'; } elseif (count($sortParams) == 2) { list($sortType, $sortDirection) = $sortParams; } if ($request->hasParameter('git_branch_slug')) { $groupRun = JenkinsGroupRunPeer::retrieveBySfGuardUserIdAndGitBranchSlug($userId, $request->getParameter('git_branch_slug')); $this->forward404If(null === $groupRun, sprintf('Unable to find build branch with branch name %s ', $request->getParameter('git_branch_slug'))); $currentGroupId = $groupRun->getId(); } else { $currentGroupId = $request->getParameter('group_run_id'); } $order = $sortDirection == 'desc' ? Criteria::DESC : Criteria::ASC; $query = new JenkinsGroupRunQuery(); $query->findBySfGuardUserId($userId); switch ($sortType) { case 'date': $query->orderByDate($order); break; case 'label': $query->orderByLabel($order); break; default: $query->orderByDate(Criteria::DESC); break; } $groupRuns = $query->find(); $dataGroupRuns = array(); foreach ($groupRuns as $groupRun) { if (null === $currentGroupId) { $currentGroupId = $groupRun->getId(); } /** @var JenkinsGroupRun $groupRun */ $result = $groupRun->getResult($jenkins); $dataGroupRuns[$groupRun->getId()] = array('label' => $groupRun->getLabel(), 'git_branch' => $groupRun->getGitBranch(), 'git_branch_slug' => $groupRun->getGitBranchSlug(), 'date' => $groupRun->getDate('Y-m-d H:i:s'), 'result' => $result, 'result_weight' => $groupRun->getResultWeight($result), 'url_view' => $this->generateUrl('branch_view', $groupRun) . '/sort/' . $sortType . '_' . $sortDirection); } if ($sortType == 'result') { $method = $sortDirection == 'asc' ? 'sortGroupRunsByResultAsc' : 'sortGroupRunsByResultDesc'; uasort($dataGroupRuns, array($this, $method)); } $currentGroupRun = JenkinsGroupRunPeer::retrieveByPK($currentGroupId); $sortMenu = $partial_url_for_sort_direction = $branch_view_url = null; if (null !== $currentGroupRun) { $sortMenu = array('label' => array('label' => 'Name', 'url' => $this->generateUrl('branch_view', $currentGroupRun) . '/sort/label_' . $sortDirection), 'date' => array('label' => 'Creation date', 'url' => $this->generateUrl('branch_view', $currentGroupRun) . '/sort/date_' . $sortDirection), 'result' => array('label' => 'Status', 'url' => $this->generateUrl('branch_view', $currentGroupRun) . '/sort/result_' . $sortDirection)); $branch_view_url = $this->generateUrl('branch_view', $currentGroupRun); $partial_url_for_sort_direction = sprintf('%s/sort/%s_', $this->generateUrl('branch_view', $currentGroupRun), $sortType); } $this->setVar('group_runs', $dataGroupRuns); $this->setVar('current_group_run_id', $currentGroupId); $this->setVar('sort_type', $sortType); $this->setVar('sort_direction', $sortDirection); $this->setVar('sort_menu', $sortMenu); $this->setVar('branch_view_url', $branch_view_url); $this->setVar('partial_url_for_sort_direction', $partial_url_for_sort_direction); $this->setVar('enabled_popover', $this->getUser()->getProfile()->getPopoverEnabled()); }