diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 32bf6b7ac5..d5ab4d0eb6 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -2879,4 +2879,20 @@ class gitlabModel extends model $html .= ''; return $html; } + + /** + * Get pipeline with api. + * + * @param int $gitlabID + * @param int $projectID + * @param string $branch + * @access public + * @return object|array + */ + public function apiGetPipeline($gitlabID, $projectID, $branch) + { + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/projects/$projectID/pipelines") . "&ref=$branch"; + return json_decode(commonModel::http($url)); + } } diff --git a/module/jenkins/config.php b/module/jenkins/config.php index 874d71aea1..f86ffd1b7c 100644 --- a/module/jenkins/config.php +++ b/module/jenkins/config.php @@ -1,5 +1,5 @@ jenkins->create = new stdclass(); $config->jenkins->edit = new stdclass(); -$config->jenkins->create->requiredFields = 'name,url'; -$config->jenkins->edit->requiredFields = 'name,url'; +$config->jenkins->create->requiredFields = 'name,url,account'; +$config->jenkins->edit->requiredFields = 'name,url,account'; diff --git a/module/job/model.php b/module/job/model.php index c3d53774e7..7bae1cf900 100644 --- a/module/job/model.php +++ b/module/job/model.php @@ -181,6 +181,15 @@ class jobModel extends model { $repo = $this->loadModel('repo')->getRepoByID($job->repo); $project = zget($repo, 'project'); + if(!empty($repo)) + { + $pipeline = $this->loadModel('gitlab')->apiGetPipeline($repo->serviceHost, $repo->serviceProject, $this->post->reference); + if(!is_array($pipeline) or empty($pipeline)) + { + dao::$errors['repo'] = $this->lang->job->engineTips->error; + return false; + } + } $job->server = (int)zget($repo, 'serviceHost', 0); $job->pipeline = json_encode(array('project' => $project, 'reference' => $this->post->reference)); @@ -298,6 +307,15 @@ class jobModel extends model { $repo = $this->loadModel('repo')->getRepoByID($job->gitlabRepo); $project = zget($repo, 'project'); + if(!empty($repo)) + { + $pipeline = $this->loadModel('gitlab')->apiGetPipeline($repo->serviceHost, $repo->serviceProject, $this->post->reference); + if(!is_array($pipeline) or empty($pipeline)) + { + dao::$errors['repo'] = $this->lang->job->engineTips->error; + return false; + } + } $job->repo = $job->gitlabRepo; $job->server = (int)zget($repo, 'serviceHost', 0); diff --git a/module/pipeline/model.php b/module/pipeline/model.php index ee8554972b..b6b2e9274c 100644 --- a/module/pipeline/model.php +++ b/module/pipeline/model.php @@ -87,6 +87,9 @@ class pipelineModel extends model ->batchCheck($this->config->pipeline->create->requiredFields, 'notempty') ->batchCheck("url", 'URL') ->check('name', 'unique', "`type` = '$type'") + ->checkIF($type == 'jenkins', 'account', 'notempty') + ->checkIF($type == 'jenkins' and !$pipeline->token, 'password', 'notempty') + ->checkIF($type == 'jenkins' and !$pipeline->password, 'token', 'notempty') ->autoCheck() ->exec(); if(dao::isError()) return false; @@ -118,6 +121,9 @@ class pipelineModel extends model ->batchCheck($this->config->pipeline->edit->requiredFields, 'notempty') ->batchCheck("url", 'URL') ->check('name', 'unique', "`type` = '$type' and id <> $id") + ->checkIF($type == 'jenkins', 'account', 'notempty') + ->checkIF($type == 'jenkins' and !$pipeline->token, 'password', 'notempty') + ->checkIF($type == 'jenkins' and !$pipeline->password, 'token', 'notempty') ->autoCheck() ->where('id')->eq($id) ->exec();