/** * Function processing to CI project creation * @param Project $project * @return mixed */ protected function processCIProjectCreation(Project $project) { $returnValues['slot_name'] = 'CI'; try { // CI job name $ciJobName = $this->getJobName($project); // Create view $jenkins_view_creation = $this->jenkinsApi->createView($project->getName()); $returnValues['data'][] = $this->setRetVal('CI View creation', 'bool', $jenkins_view_creation); // Copy default job $jenkins_job_copy = $this->jenkinsApi->copyJob($ciJobName); $returnValues['data'][] = $this->setRetVal('CI Job copy', 'bool', $jenkins_job_copy); // Add Project to view $jenkins_job_to_view = $this->jenkinsApi->addJobToView($project->getName(), $ciJobName); $returnValues['data'][] = $this->setRetVal('CI Job add to view', 'bool', $jenkins_job_to_view); // Add ci remote access $ci = new ContinuousIntegration(); // Selecting the right uri $ci->setAccessUrl(sprintf('%s/job/%s', $this->externalUri == "none" ? $this->ciBaseUrl : $this->externalUri, $ciJobName)); $ci->setProject($project); $ci->setCiName($ciJobName); $ci->setParametrized(true); $ci->setParameters(array(json_encode(array('name' => 'PIPELINE_VERSION_UPPER', 'type' => 'string', 'default' => '${BUILD_NUMBER}', 'description' => 'Define the pipeline version', 'hide' => true)), json_encode(array('name' => 'CUSTOM_WORKSPACE', 'type' => 'string', 'default' => '${WORKSPACE}', 'description' => 'Define the workspace place', 'hide' => true)))); $ci->setActive(false); $this->em->persist($ci); $this->em->flush(); } catch (\Exception $e) { $returnValues['data'][] = $this->setRetVal('CI ERROR', 'string', 'Unexpected error'); $returnValues['data'][] = $this->setRetVal('CI View creation', 'bool', false); $returnValues['data'][] = $this->setRetVal('CI Job copy', 'bool', false); $returnValues['data'][] = $this->setRetVal('CI Job add to view', 'bool', false); } return $returnValues; }
/** * Get remote job progression * @param ContinuousIntegration $ci * @return mixed */ public function getProgression(ContinuousIntegration $ci) { // Fast Return in case of server stopped if (!$this->isServerAvailable()) { return null; } $build = $this->jenkinsClient->getJob($ci->getCiName())->getBuilds()[0]; $progress = $build->getProgress(); // dump($progress); return $progress; }