* Run gitlab pipeline.
This commit is contained in:
@@ -13,6 +13,8 @@ $lang->compile->result = '构建结果';
|
||||
$lang->compile->statusList['success'] = '成功';
|
||||
$lang->compile->statusList['failure'] = '失败';
|
||||
$lang->compile->statusList['created'] = '新建';
|
||||
$lang->compile->statusList['pending'] = '队列中';
|
||||
$lang->compile->statusList['running'] = '运行中';
|
||||
$lang->compile->statusList['building'] = '构建中';
|
||||
$lang->compile->statusList['create_fail'] = '创建失败';
|
||||
$lang->compile->statusList['timeout'] = '执行超时';
|
||||
|
||||
@@ -15,24 +15,43 @@ class gitlabpipeline extends control
|
||||
*
|
||||
* @param int $jobID
|
||||
* @access public
|
||||
* @return int|false
|
||||
* @return string|false
|
||||
*/
|
||||
public function runPipeline($jobID)
|
||||
{
|
||||
$job = $this->loadModel('job')->getByID($jobID);
|
||||
$pipeline = $this->gitlabpipeline->apiCreatePipeline($job->server, $job->pipeline, array('ref' => 'master'));
|
||||
|
||||
if(isset($pipeline->id))
|
||||
$now = helper::now();
|
||||
$job = $this->loadModel('job')->getByID($jobID);
|
||||
$status = $job->lastStatus;
|
||||
if($status and $status != 'success' and $status != 'create_fail')
|
||||
{
|
||||
a($pipeline); // todo(dingguodong) save $pipeline->id to zt_compile, zt_job.
|
||||
echo js::alert(sprintf($this->lang->gitlabpipeline->sendExec, $pipeline->status));
|
||||
$compile = $this->loadModel('compile')->getLastResult($jobID);
|
||||
if($compile)
|
||||
{
|
||||
$pipeline = $this->gitlabpipeline->apiGetPiplineByID($job->server, $job->pipeline, $compile->queue);
|
||||
$this->dao->update(TABLE_COMPILE)->set('status')->eq($pipeline->status)->set('updateDate')->eq($now)->where('id')->eq($compile->id)->exec();
|
||||
$this->dao->update(TABLE_JOB)->set('lastExec')->eq($now)->set('lastStatus')->eq($pipeline->status)->where('id')->eq($jobID)->exec();
|
||||
}
|
||||
echo js::alert($this->lang->gitlabpipeline->execError);
|
||||
die(js::reload('parent'));
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$pipeline = $this->gitlabpipeline->apiCreatePipeline($job->server, $job->pipeline, array('ref' => 'master'));
|
||||
$status = isset($pipeline->id) ? 'created' : 'create_fail';
|
||||
|
||||
$this->dao->update(TABLE_JOB)->set('lastExec')->eq($now)->set('lastStatus')->eq($status)->where('id')->eq($jobID)->exec();
|
||||
|
||||
if(!isset($pipeline->id)) return false;
|
||||
$build = new stdclass;
|
||||
$build->job = $jobID;
|
||||
$build->name = $job->name;
|
||||
$build->queue = $pipeline->id; // use `queue` to save gitlab project pipeline id.
|
||||
$build->status = $pipeline->status;
|
||||
$build->createdBy = $this->app->user->account;
|
||||
$build->createdDate = $now;
|
||||
$this->dao->insert(TABLE_COMPILE)->data($build)->exec();
|
||||
|
||||
echo js::alert(sprintf($this->lang->gitlabpipeline->sendExec, $pipeline->status));
|
||||
die(js::reload('parent'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<?php
|
||||
$lang->gitlabpipeline->runPipeline = '运行流水线'; // run pipeline manually
|
||||
$lang->gitlabpipeline->sendExec = '流水线已运行!当前状态为:%s';
|
||||
$lang->gitlabpipeline->execError = '不要重复运行流水线,请等待运行结果!';
|
||||
|
||||
@@ -24,7 +24,7 @@ class gitlabpipelineModel extends model
|
||||
|
||||
public function apiGetPiplineByID($gitlabID, $projectID, $pipelineID)
|
||||
{
|
||||
$url = sprintf($this->loadModel('gitlab')->getApiRoot($gitlabID), "/projects/{$projectID}/pipelines/{$piplinesID}");
|
||||
$url = sprintf($this->loadModel('gitlab')->getApiRoot($gitlabID), "/projects/{$projectID}/pipelines/{$pipelineID}");
|
||||
return json_decode(commonModel::http($url));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user