fix the bug about jenkins build request and status checking
This commit is contained in:
@@ -158,8 +158,6 @@ class ci extends control
|
||||
*/
|
||||
public function exeJob($id)
|
||||
{
|
||||
error_log("===exeJob " . $id);
|
||||
|
||||
$this->ci->exeJob($id);
|
||||
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ $lang->job->tagEx = 'build_#15, to build Jenkins job that id is 15.';
|
||||
$lang->job->commitEx = 'start build #15, to build Jenkins job that id is 15.';
|
||||
$lang->job->cronSample = 'e.g. 0 0 2 * * 2-6/1 means 2:00 a.m. every weekday.';
|
||||
|
||||
$lang->job->buildStatusList = array('success' => 'Success', 'fail' => 'Fail', 'created' => 'Created', 'building' => 'Building');
|
||||
$lang->job->buildStatusList = array('success' => 'Success', 'fail' => 'Fail', 'created' => 'Created', 'building' => 'Building', 'create_fail' => 'Fail to create', 'timeout' => 'Exec Timeout');
|
||||
$lang->job->dayTypeList = array('workDay' => 'Weekdays', 'everyDay' => 'Every Day');
|
||||
$lang->job->triggerTypeList = array('tag' => 'Tag', 'commit' => 'Code Commit', 'schedule' => 'Schedule');
|
||||
$lang->job->scheduleTypeList = array('cron' => 'Cron', 'custom' => 'Custom');
|
||||
|
||||
@@ -43,7 +43,7 @@ $lang->job->tagEx = 'build_#15,其中15为Jenkins任务编号';
|
||||
$lang->job->commitEx = 'start build #15,其中15为Jenkins任务编号';
|
||||
$lang->job->cronSample = '如 0 0 2 * * 2-6/1 表示每个工作日凌晨2点';
|
||||
|
||||
$lang->job->buildStatusList = array('success' => '成功', 'fail' => '失败', 'created' => '新建', 'building' => '构建中');
|
||||
$lang->job->buildStatusList = array('success' => '成功', 'fail' => '失败', 'created' => '新建', 'building' => '构建中', 'create_fail' => '创建失败', 'timeout' => '执行超时');
|
||||
$lang->job->dayTypeList = array('workDay' => '工作日', 'everyDay' => '每天');
|
||||
$lang->job->buildTypeList = array('build' => '仅构建', 'buildAndDeploy' => '构建部署', 'buildAndTest' => '构建测试');
|
||||
$lang->job->triggerTypeList = array('tag' => '打标签', 'commit' => '代码提交注释', 'schedule' => '定时计划');
|
||||
|
||||
+17
-18
@@ -184,11 +184,9 @@ class ciModel extends model
|
||||
->where('job.id')->eq($jobID)
|
||||
->fetch();
|
||||
|
||||
$po->password = base64_decode($po->password);
|
||||
|
||||
$jenkinsServer = $po->serviceUrl;
|
||||
$jenkinsUser = $po->account;
|
||||
$jenkinsTokenOrPassword = $po->token ? $po->token : $po->password;
|
||||
$jenkinsTokenOrPassword = $po->token ? $po->token : base64_decode($po->password);
|
||||
|
||||
$r = '://' . $jenkinsUser . ':' . $jenkinsTokenOrPassword . '@';
|
||||
$jenkinsServer = str_replace('://', $r, $jenkinsServer);
|
||||
@@ -248,7 +246,7 @@ class ciModel extends model
|
||||
$build->cijob = $job->jobId;
|
||||
$build->name = $job->jobName;
|
||||
$build->queueItem = $job->queueItem;
|
||||
$build->status = 'created';
|
||||
$build->status = $job->queueItem ? 'created' : 'create_fail';
|
||||
$build->createdBy = $this->app->user->account;
|
||||
$build->createdDate = helper::now();
|
||||
|
||||
@@ -281,23 +279,20 @@ class ciModel extends model
|
||||
*/
|
||||
public function checkBuildStatus()
|
||||
{
|
||||
$pos = $this->dao->select('build.*, job.jenkinsJob, jenkins.name jenkinsName,jenkins.serviceUrl,jenkins.credentials')
|
||||
$pos = $this->dao->select('build.*, job.jenkinsJob, jenkins.name jenkinsName,jenkins.serviceUrl,jenkins.account,jenkins.token,jenkins.password')
|
||||
->from(TABLE_CI_BUILD)->alias('build')
|
||||
->leftJoin(TABLE_CI_JOB)->alias('job')->on('build.cijob=job.id')
|
||||
->leftJoin(TABLE_JENKINS)->alias('jenkins')->on('job.jenkins=jenkins.id')
|
||||
->where('build.status')->ne('success')
|
||||
->andWhere('build.status')->ne('fail')
|
||||
->andWhere('build.status')->ne('timeout')
|
||||
->andWhere('build.createdDate')->gt(date(DT_DATETIME1, strtotime("-1 day")))
|
||||
->fetchAll();
|
||||
|
||||
foreach($pos as $po) {
|
||||
$credentials = $this->loadModel('cicredentials')->getByID($po->credentials); // jenkins must use a token or account credentials
|
||||
if ($credentials->type === 'token') {
|
||||
$jenkinsTokenOrPassword = $credentials->token;
|
||||
} else if ($credentials->type === 'account') {
|
||||
$jenkinsTokenOrPassword = $credentials->password;
|
||||
}
|
||||
$jenkinsUser = $credentials->username;
|
||||
$jenkinsServer = $po->serviceUrl;
|
||||
$jenkinsUser = $po->account;
|
||||
$jenkinsTokenOrPassword = $po->token ? $po->token : base64_decode($po->password);
|
||||
|
||||
$r = '://' . $jenkinsUser . ':' . $jenkinsTokenOrPassword . '@';
|
||||
$jenkinsServer = str_replace('://', $r, $jenkinsServer);
|
||||
@@ -309,7 +304,7 @@ class ciModel extends model
|
||||
$response = common::http($infoUrl);
|
||||
$buildInfo = json_decode($response);
|
||||
$result = strtolower($buildInfo->result);
|
||||
$this->updateCibuildStatus($po, $result);
|
||||
$this->updateBuildStatus($po, $result);
|
||||
|
||||
$logUrl = sprintf('%s/job/%s/%s/consoleText', $jenkinsServer, $po->jenkinsJob, $po->queueItem);
|
||||
$response = common::http($logUrl);
|
||||
@@ -327,10 +322,10 @@ class ciModel extends model
|
||||
$buildInfo = json_decode($response);
|
||||
|
||||
if ($buildInfo->building) {
|
||||
$this->updateCibuildStatus($po, 'building');
|
||||
$this->updateBuildStatus($po, 'building');
|
||||
} else {
|
||||
$result = strtolower($buildInfo->result);
|
||||
$this->updateCibuildStatus($po, $result);
|
||||
$this->updateBuildStatus($po, $result);
|
||||
|
||||
$logUrl = $buildInfo->url . 'logText/progressiveText/api/json';
|
||||
$logUrl = str_replace('://', $r, $logUrl);
|
||||
@@ -345,9 +340,13 @@ class ciModel extends model
|
||||
}
|
||||
}
|
||||
|
||||
public function sendBuildRequest($url)
|
||||
/**
|
||||
* @param $url
|
||||
* @return false|mixed|string
|
||||
*/
|
||||
public function sendBuildRequest($url) // not to use common http
|
||||
{
|
||||
if(!extension_loaded('curl')) return json_encode(array('result' => 'fail', 'message' => $lang->error->noCurlExt));
|
||||
if(!extension_loaded('curl')) return json_encode(array('result' => 'fail', 'message' => $this->lang->error->noCurlExt));
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
|
||||
@@ -365,7 +364,7 @@ class ciModel extends model
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLINFO_HEADER_OUT, TRUE);
|
||||
//
|
||||
|
||||
curl_setopt ($curl , CURLOPT_HEADER, 1 );
|
||||
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
|
||||
@@ -510,6 +510,7 @@ $lang->error->pasteImg = 'Images are not allowed to be pasted in your bro
|
||||
$lang->error->noData = 'No data.';
|
||||
$lang->error->editedByOther = 'This record might have been changed. Please refresh and try to edit again!';
|
||||
$lang->error->tutorialData = 'No data can be imported in tutorial mode. Please quit tutorial first!';
|
||||
$lang->error->noCurlExt = 'No Curl module installed';
|
||||
|
||||
/* Page info. */
|
||||
$lang->pager = new stdclass();
|
||||
|
||||
@@ -512,6 +512,8 @@ $lang->error->noData = '没有数据';
|
||||
$lang->error->editedByOther = '该记录可能已经被改动。请刷新页面重新编辑!';
|
||||
$lang->error->tutorialData = '新手模式下不会插入数据,请退出新手模式操作';
|
||||
|
||||
$lang->error->noCurlExt = '服务器未安装Curl模块。';
|
||||
|
||||
/* 分页信息。*/
|
||||
$lang->pager = new stdclass();
|
||||
$lang->pager->noRecord = "暂时没有记录";
|
||||
|
||||
Reference in New Issue
Block a user