* Fix exec gitlab job bug and adjust exec job function.

This commit is contained in:
Guan Xiying
2021-09-06 17:29:37 +08:00
parent ddfe2479ac
commit a5ceffb6cf
6 changed files with 30 additions and 10 deletions
+2 -1
View File
@@ -877,8 +877,9 @@ class gitlabModel extends model
*/
public function apiCreatePipeline($gitlabID, $projectID, $params)
{
if(!is_string($params)) $params = json_encode($params);
$url = sprintf($this->getApiRoot($gitlabID), "/projects/{$projectID}/pipeline");
return json_decode(commonModel::http($url, $reference, null, array("Content-Type: application/json")));
return json_decode(commonModel::http($url, $params, null, array("Content-Type: application/json")));
}
/**
+6 -4
View File
@@ -306,15 +306,17 @@ class job extends control
$job = $this->job->getByID($id);
if(strtolower($job->engine) == 'gitlab')
{
if(!isset($job->reference) or !$job->reference) $this->locate(inlink('edit', "id=$id"));
if(!isset($job->reference) or !$job->reference)
{
return $this->send(array('result' => 'fail', 'message' => $this->lang->job->setReferenceTips, 'locate' => inlink('edit', "id=$id")));
}
}
$compile = $this->job->exec($id);
if(dao::isError()) die(js::error(dao::getError()));
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->app->loadLang('compile');
echo js::alert(sprintf($this->lang->job->sendExec, zget($this->lang->compile->statusList, $compile->status)));
die(js::reload('parent'));
return $this->send(array('result' => 'success', 'message' => sprintf($this->lang->job->sendExec, zget($this->lang->compile->statusList, $compile->status))));
}
/**
+16
View File
@@ -0,0 +1,16 @@
$(document).ready(function()
{
$('.icon-job-exec').parent().click(function()
{
link = $(this).attr('href');
$.getJSON(link, function(response)
{
if(response.result == 'success') bootbox.alert(response.message);
if(response.result != 'success') bootbox.alert(response.message, function()
{
if(typeof(response.locate) == 'string') location.href = response.locate;
});
});
return false;
});
});
+1
View File
@@ -86,3 +86,4 @@ $lang->job->pipelineVariables = "变量";
$lang->job->pipelineVariablesKeyPlaceHolder = "输入变量的名称";
$lang->job->pipelineVariablesValuePlaceHolder = "输入变量的值";
$lang->job->pipelineVariablesTips = "指定要在此次运行中使用的变量值。CI/CD设置中指定的值将用作默认值。";
$lang->job->setReferenceTips = "在执行构建前,请先设置构建的 Reference.";
+4 -4
View File
@@ -436,10 +436,10 @@ class jobModel extends model
*/
public function execGitlabPipeline($job, $compileID)
{
list($gitlabProject, $gitlabReference) = json_decode($job->pipeline);
$pipeline = json_decode($job->pipeline);
$pipelineParams = new stdclass;
$pipelineParams->ref = $gitlabReference;
$pipelineParams->ref = $pipeline->reference;
$customParams = json_decode($job->customParam);
$variables = array();
@@ -453,12 +453,12 @@ class jobModel extends model
$variables[] = $variable;
}
$pipelineParams->variables = $variables;
if(!empty($variables)) $pipelineParams->variables = $variables;
$compile = new stdclass;
$compile->id = $compileID;
$pipeline = $this->loadModel('gitlab')->apiCreatePipeline($job->server, $gitlabProject, $pipelineParams);
$pipeline = $this->loadModel('gitlab')->apiCreatePipeline($job->server, $pipeline->project, $pipelineParams);
if(empty($pipeline->id)) $compile->status = 'create_fail';
if(!empty($pipeline->id))
+1 -1
View File
@@ -67,7 +67,7 @@
<?php
common::printIcon('compile', 'browse', "jobID=$id", '', 'list', 'history');
common::printIcon('job', 'edit', "jobID=$id", '', 'list', 'edit');
common::printIcon('job', 'exec', "jobID=$id", '', 'list', 'play', 'hiddenwin');
common::printIcon('job', 'exec', "jobID=$id", '', 'list', 'play');
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>