From 4eaf583ea8f4d90ff26347abe02ccb61f2178a83 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Wed, 15 Sep 2021 09:55:42 +0800 Subject: [PATCH] * Fix bug when exec gitlab pipeline in job module. --- module/ci/model.php | 21 ++++++++++++++++----- module/compile/control.php | 8 ++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/module/ci/model.php b/module/ci/model.php index 2af08d66f9..9943a6fcaa 100644 --- a/module/ci/model.php +++ b/module/ci/model.php @@ -118,7 +118,7 @@ class ciModel extends model /** * Sync gitlab task status. - * + * * @param object $compile * @access public * @return void @@ -127,10 +127,21 @@ class ciModel extends model { $this->loadModel('gitlab'); - $now = helper::now(); - $pipeline = $this->gitlab->apiGetSinglePipeline($compile->server, $compile->pipeline, $compile->queue); - $jobs = $this->gitlab->apiGetJobs($compile->server, $compile->pipeline, $compile->queue); + $now = helper::now(); + /* The value of `$compile->pipeline` is like `'{"project":"46","reference":"master"}'` in current design. */ + $pipeline = json_decode($compile->pipeline); + $compile->project = isset($pipeline->project) ? $pipeline->project : $compile->pipeline; + + $pipeline = $this->gitlab->apiGetSinglePipeline($compile->server, $compile->project, $compile->queue); + if(!isset($pipeline->id) or isset($pipeline->message)) /* The pipeline is not available. */ + { + $pipeline->status = 'create_fail'; /* Set the status to fail. */ + $this->dao->update(TABLE_JOB)->set('lastExec')->eq($now)->set('lastStatus')->eq($pipeline->status)->where('id')->eq($compile->job)->exec(); + return false; + } + + $jobs = $this->gitlab->apiGetJobs($compile->server, $compile->project, $compile->queue); $data = new stdclass; $data->status = $pipeline->status; $data->updateDate = $now; @@ -140,7 +151,7 @@ class ciModel extends model if(empty($job->duration) or $job->duration == '') $job->duration = '-'; $data->logs = ">>> Job: $job->name, Stage: $job->stage, Status: $job->status, Duration: $job->duration Sec\r\n "; $data->logs .= "Job URL: web_url\" target='_blank'>$job->web_url \r\n"; - $data->logs .= $this->transformAnsiToHtml($this->gitlab->apiGetJobLog($compile->server, $compile->pipeline, $job->id)); + $data->logs .= $this->transformAnsiToHtml($this->gitlab->apiGetJobLog($compile->server, $compile->project, $job->id)); } $this->dao->update(TABLE_COMPILE)->data($data)->where('id')->eq($compile->id)->exec(); diff --git a/module/compile/control.php b/module/compile/control.php index d40e36798b..aa81b14e1d 100644 --- a/module/compile/control.php +++ b/module/compile/control.php @@ -12,10 +12,10 @@ class compile extends control { /** - * Construct - * - * @param string $moduleName - * @param string $methodName + * Construct + * + * @param string $moduleName + * @param string $methodName * @access public * @return void */