* Use job::exec to execute one gitlab ci job.

This commit is contained in:
Guan Xiying
2021-07-26 15:51:26 +08:00
parent a311c88903
commit b4308635cd
3 changed files with 17 additions and 8 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ $('#repo').change(function()
}
);
var type = 'Git';
var type = 'Git';
if(typeof(repoTypes[repoID]) != 'undefined') type = repoTypes[repoID];
$('.svn-fields').addClass('hidden');
+15 -5
View File
@@ -308,7 +308,7 @@ class jobModel extends model
*/
public function exec($id)
{
$job = $this->dao->select('t1.id,t1.name,t1.product,t1.repo,t1.pipeline,t1.triggerType,t1.atTime,t1.customParam,t2.name as jenkinsName,t2.url,t2.account,t2.token,t2.password')
$job = $this->dao->select('t1.id,t1.name,t1.product,t1.repo,t1.server,t1.pipeline,t1.triggerType,t1.atTime,t1.customParam,t1.engine,t2.name as jenkinsName,t2.url,t2.account,t2.token,t2.password')
->from(TABLE_JOB)->alias('t1')
->leftJoin(TABLE_PIPELINE)->alias('t2')->on('t1.server=t2.id')
->where('t1.id')->eq($id)
@@ -319,7 +319,6 @@ class jobModel extends model
$build->job = $job->id;
$build->name = $job->name;
$url = $this->loadModel('compile')->getBuildUrl($job);
$now = helper::now();
$data = new stdclass();
$repo = $this->loadModel('repo')->getRepoById($job->repo);
@@ -378,10 +377,21 @@ class jobModel extends model
}
$compile = new stdclass();
$compile->queue = $this->loadModel('ci')->sendRequest($url->url, $data, $url->userPWD);
$compile->status = $compile->queue ? 'created' : 'create_fail';
$this->dao->update(TABLE_COMPILE)->data($compile)->where('id')->eq($compileID)->exec();
if($job->engine == 'jenkins')
{
$url = $this->loadModel('compile')->getBuildUrl($job);
$compile->queue = $this->loadModel('ci')->sendRequest($url->url, $data, $url->userPWD);
$compile->status = $compile->queue ? 'created' : 'create_fail';
}
elseif($job->engine == 'gitlab')
{
$pipeline = $this->loadModel('gitlabpipeline')->apiCreatePipeline($job->server, $job->pipeline, array('ref' => 'master'));
$compile->queue = $pipeline->id;
$compile->status = zget($pipeline, 'status', 'create_fail');
}
$this->dao->update(TABLE_COMPILE)->data($compile)->where('id')->eq($compileID)->exec();
$this->dao->update(TABLE_JOB)->set('lastExec')->eq($now)->set('lastStatus')->eq($compile->status)->where('id')->eq($job->id)->exec();
return $compile->status;
+1 -2
View File
@@ -57,8 +57,7 @@
<?php
common::printIcon('compile', 'browse', "jobID=$id", '', 'list', 'history');
common::printIcon('job', 'edit', "jobID=$id", '', 'list', 'edit');
if(strtolower($job->engine) == 'jenkins') common::printIcon('job', 'exec', "jobID=$id", '', 'list', 'play', 'hiddenwin');
if(strtolower($job->engine) == 'gitlab') common::printIcon('gitlabpipeline', 'runPipeline', "jobID=$id", '', 'list', 'play', 'hiddenwin');
common::printIcon('job', 'exec', "jobID=$id", '', 'list', 'play', 'hiddenwin');
if(common::hasPriv('job', 'delete')) echo html::a($this->createLink('job', 'delete', "jobID=$id"), '<i class="icon-trash"></i>', 'hiddenwin', "title='{$lang->job->delete}' class='btn'");
?>
</td>