* Fix exec gitlab pipeline function.
This commit is contained in:
@@ -266,6 +266,24 @@ class gitlabModel extends model
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ref option menus.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param int $projectID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getRefOptions($gitlabID, $projectID)
|
||||
{
|
||||
$refList = array();
|
||||
$branches = $this->loadModel('gitlab')->apiGetBranches($gitlabID, $projectID);
|
||||
$tags = $this->loadModel('gitlab')->apiGetTags($gitlabID, $projectID);
|
||||
foreach($branches as $branch) $refList[] = "Branch::" . $branch->name;
|
||||
foreach($tags as $tag) $refList[] = "Tag::" . $tag->name;
|
||||
return $refList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a gitlab.
|
||||
*
|
||||
|
||||
+39
-49
@@ -235,65 +235,55 @@ class job extends control
|
||||
/**
|
||||
* Exec a job.
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $id
|
||||
* @param string $showForm
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function exec($id)
|
||||
public function exec($id, $showForm = 'no')
|
||||
{
|
||||
$status = $this->job->exec($id);
|
||||
if($showForm == 'yes' or $_POST)
|
||||
{
|
||||
$job = $this->job->getByID($id);
|
||||
$refList = $this->loadModel('gitlab')->getRefOptions($job->server, $job->pipeline);
|
||||
|
||||
if($_POST)
|
||||
{
|
||||
$reference = new stdclass;
|
||||
$reference->ref = explode("::", $refList[$this->post->ref])[1];
|
||||
|
||||
$variables = array();
|
||||
foreach($this->post->keys as $key => $field)
|
||||
{
|
||||
$variable = array();
|
||||
if(!trim($this->post->values[$key])) continue;
|
||||
$variable['key'] = $field;
|
||||
$variable['value'] = $this->post->values[$key];
|
||||
$variable['variable_type'] = "env_var";
|
||||
|
||||
$variables[] = $variable;
|
||||
}
|
||||
|
||||
$reference->variables = $variables;
|
||||
$compile = $this->job->exec($id, json_encode($reference));
|
||||
return $this->send(array('result' => 'success', 'message' => $this->lang->job->execSuccess, 'locate' => $this->createLink('compile', 'logs', "buildID={$compile->id}")));
|
||||
}
|
||||
|
||||
$this->view->title = $this->lang->job->runPipeline;
|
||||
$this->view->refList = $refList;
|
||||
$this->view->job = $job;
|
||||
$this->view->pipelineTips = $this->lang->job->pipeline->pipelineTips;
|
||||
return $this->display();
|
||||
}
|
||||
|
||||
$compile = $this->job->exec($id);
|
||||
if(dao::isError()) die(js::error(dao::getError()));
|
||||
|
||||
$this->app->loadLang('compile');
|
||||
echo js::alert(sprintf($this->lang->job->sendExec, zget($this->lang->compile->statusList, $status)));
|
||||
echo js::alert(sprintf($this->lang->job->sendExec, zget($this->lang->compile->statusList, $compile->status)));
|
||||
die(js::reload('parent'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Run GitLab pipeline for a job.
|
||||
*
|
||||
* @param int $id
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function runPipeline($id)
|
||||
{
|
||||
$job = $this->job->getByID($id);
|
||||
|
||||
$refList = array();
|
||||
$branches = $this->loadModel('gitlab')->apiGetBranches($job->server, $job->pipeline);
|
||||
$tags = $this->loadModel('gitlab')->apiGetTags($job->server, $job->pipeline);
|
||||
foreach($branches as $branch) $refList[] = "branch::" . $branch->name;
|
||||
foreach($tags as $tag) $refList[] = "tag::" . $tag->name;
|
||||
|
||||
if($_POST)
|
||||
{
|
||||
$reference = new stdclass;
|
||||
$reference->ref = explode("::", $refList[$this->post->ref])[1];
|
||||
|
||||
$variable = array();
|
||||
$variablesParam = array();
|
||||
$variables = array_combine(array_values($this->post->keys), array_values($this->post->values));
|
||||
foreach($variables as $key => $value)
|
||||
{
|
||||
if($key == "") continue;
|
||||
$variable['key'] = $key;
|
||||
$variable['variable_type'] = "env_var";
|
||||
$variable['value'] = $value;
|
||||
$variablesParam[] = $variable;
|
||||
}
|
||||
$reference->variables = $variablesParam;
|
||||
$reference = json_encode($reference);
|
||||
$this->job->exec($id, $reference);
|
||||
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
|
||||
}
|
||||
|
||||
$this->view->title = $this->lang->job->runPipeline;
|
||||
$this->view->refList = $refList;
|
||||
$this->view->pipelineTips = $this->lang->job->pipeline->pipelineTips;
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX: Get product by repo.
|
||||
*
|
||||
|
||||
@@ -10,6 +10,7 @@ $lang->job->delete = '删除构建任务';
|
||||
$lang->job->confirmDelete = '确认删除该构建任务';
|
||||
$lang->job->dirChange = '目录改动';
|
||||
$lang->job->buildTag = '打标签';
|
||||
$lang->job->execSuccess = '执行成功';
|
||||
|
||||
$lang->job->browseAction = '构建任务列表';
|
||||
|
||||
|
||||
@@ -378,6 +378,7 @@ class jobModel extends model
|
||||
}
|
||||
|
||||
$compile = new stdclass();
|
||||
$compile->id = $compileID;
|
||||
|
||||
if($job->engine == 'jenkins')
|
||||
{
|
||||
@@ -402,6 +403,6 @@ class jobModel extends model
|
||||
$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;
|
||||
return $compile;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
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('job', 'runPipeline', "jobID=$id", '', 'list', 'play', '');
|
||||
if(strtolower($job->engine) == 'gitlab') common::printIcon('job', 'exec', "jobID=$id&showForm=yes", '', 'list', 'play', '', '', false, "data-toggle='modal'");
|
||||
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>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php include '../../common/view/header.html.php';?>
|
||||
<form id='childrenForm' method='post' target='hiddenwin'>
|
||||
<?php include '../../common/view/header.lite.html.php';?>
|
||||
<form id='childrenForm' class='form-ajax' action="<?php echo inlink('exec', "jobID={$job->id}");?>" method='post'>
|
||||
<table class='table table-form table-auto'>
|
||||
<tr>
|
||||
<td><?php echo $pipelineTips;?></td>
|
||||
@@ -29,4 +29,4 @@
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<?php include '../../common/view/footer.html.php';?>
|
||||
<?php include '../../common/view/footer.lite.html.php';?>
|
||||
Reference in New Issue
Block a user