* finish task #6858,6895.
This commit is contained in:
+71
-5
@@ -33,11 +33,72 @@ class ci extends control
|
||||
$scheduleJobs = $this->loadModel('integration')->getListByTriggerType('schedule');
|
||||
|
||||
$week = date('w');
|
||||
$this->loadModel('compile');
|
||||
foreach($scheduleJobs as $job)
|
||||
{
|
||||
if(strpos($job->scheduleDay, $week) !== false) $this->integration->exec($job->id);
|
||||
if(strpos($job->scheduleDay, $week) !== false) $this->compile->createByIntegration($job->id);
|
||||
}
|
||||
die('success');
|
||||
echo 'success';
|
||||
}
|
||||
|
||||
/**
|
||||
* Exec compile.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function exec()
|
||||
{
|
||||
$compiles = $this->loadModel('compile')->getUnexecutedList();
|
||||
foreach($compiles as $compile) $this->compile->execByCompile($compile);
|
||||
|
||||
$integrations = $this->loadModel('integration')->getListByTriggerType('tag');
|
||||
|
||||
$repoIdList = array();
|
||||
$repos = array();
|
||||
foreach($integrations as $integration) $repoIdList[$integration->id] = $integration->id;
|
||||
if($repoIdList) $repos = $this->loadModel('repo')->getByIdList($repoIdList);
|
||||
|
||||
foreach($integrations as $integration)
|
||||
{
|
||||
$repo = zget($repos, $integration->repo, null);
|
||||
if(empty($repo)) continue;
|
||||
|
||||
$scm = $repo->SCM == 'Git' ? 'git' : 'svn';
|
||||
$savedTag = $this->loadModel($scm)->getSavedTag($repo->id);
|
||||
|
||||
$tags = $this->$scm->getRepoTags($repo, $scm == 'svn' ? $integration->svnFolder : '');
|
||||
if(!empty($tags))
|
||||
{
|
||||
$arriveLastTag = false;
|
||||
foreach($tags as $tag)
|
||||
{
|
||||
/* Get the last build tag position */
|
||||
if($scm == 'git')
|
||||
{
|
||||
if(!empty($savedTag) && !$arriveLastTag) continue;
|
||||
if(!empty($savedTag) && $tag == $savedTag)
|
||||
{
|
||||
$arriveLastTag = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
elseif($scm == 'svn')
|
||||
{
|
||||
if(isset($savedTag[$tag])) continue;
|
||||
$tag = rtrim($repo->path , '/') . '/' . trim($integration->svnFolder, '/') . '/' . $tag;
|
||||
}
|
||||
|
||||
$tagData = new stdclass();
|
||||
$tagData->PARAM_TAG = $tag;
|
||||
$this->compile->execByIntegration($integration->id, $tagData);
|
||||
}
|
||||
|
||||
if($scm == 'svn') $tag = json_encode($tags);
|
||||
$this->$scm->saveLastTag($tag, $repo->id);
|
||||
}
|
||||
}
|
||||
echo 'success';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,8 +110,13 @@ class ci extends control
|
||||
public function checkBuildStatus()
|
||||
{
|
||||
$this->ci->checkBuildStatus();
|
||||
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
|
||||
$this->send(array('result' => 'success'));
|
||||
if(dao::isError())
|
||||
{
|
||||
echo json_encode(dao::getError());
|
||||
}
|
||||
else
|
||||
{
|
||||
echo 'success';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+28
-33
@@ -31,7 +31,7 @@ class ciModel extends model
|
||||
*/
|
||||
public function checkBuildStatus()
|
||||
{
|
||||
$pos = $this->dao->select('t1.*, t2.jenkinsJob, t3.name jenkinsName,t3.serviceUrl,t3.account,t3.token,t3.password')
|
||||
$compiles = $this->dao->select('t1.*, t2.jenkinsJob, t3.name jenkinsName,t3.serviceUrl,t3.account,t3.token,t3.password')
|
||||
->from(TABLE_COMPILE)->alias('t1')
|
||||
->leftJoin(TABLE_INTEGRATION)->alias('t2')->on('t1.cijob=t2.id')
|
||||
->leftJoin(TABLE_JENKINS)->alias('t3')->on('t2.jenkins=t3.id')
|
||||
@@ -41,59 +41,59 @@ class ciModel extends model
|
||||
->andWhere('t1.createdDate')->gt(date(DT_DATETIME1, strtotime("-1 day")))
|
||||
->fetchAll();
|
||||
|
||||
foreach($pos as $po)
|
||||
foreach($compiles as $compile)
|
||||
{
|
||||
$jenkinsServer = $po->serviceUrl;
|
||||
$jenkinsUser = $po->account;
|
||||
$jenkinsPassword = $po->token ? $po->token : base64_decode($po->password);
|
||||
$jenkinsServer = $compile->serviceUrl;
|
||||
$jenkinsUser = $compile->account;
|
||||
$jenkinsPassword = $compile->token ? $compile->token : base64_decode($compile->password);
|
||||
|
||||
$jenkinsAuth = '://' . $jenkinsUser . ':' . $jenkinsPassword . '@';
|
||||
$jenkinsServer = str_replace('://', $jenkinsAuth, $jenkinsServer);
|
||||
$queueUrl = sprintf('%s/queue/item/%s/api/json', $jenkinsServer, $po->queueItem);
|
||||
$queueUrl = sprintf('%s/queue/item/%s/api/json', $jenkinsServer, $compile->queueItem);
|
||||
|
||||
$response = common::http($queueUrl);
|
||||
if(strripos($response, "404") > -1)
|
||||
{ // queue expired, use another api
|
||||
$infoUrl = sprintf('%s/job/%s/%s/api/json', $jenkinsServer, $po->jenkinsJob, $po->queueItem);
|
||||
$response = common::http($infoUrl);
|
||||
{
|
||||
/* Queue expired, use another api. */
|
||||
$infoUrl = sprintf('%s/job/%s/%s/api/json', $jenkinsServer, $compile->jenkinsJob, $compile->queueItem);
|
||||
$response = common::http($infoUrl);
|
||||
$buildInfo = json_decode($response);
|
||||
$result = strtolower($buildInfo->result);
|
||||
$this->updateBuildStatus($po, $result);
|
||||
$result = strtolower($buildInfo->result);
|
||||
$this->updateBuildStatus($compile, $result);
|
||||
|
||||
$logUrl = sprintf('%s/job/%s/%s/consoleText', $jenkinsServer, $po->jenkinsJob, $po->queueItem);
|
||||
$logUrl = sprintf('%s/job/%s/%s/consoleText', $jenkinsServer, $compile->jenkinsJob, $compile->queueItem);
|
||||
$response = common::http($logUrl);
|
||||
$logs = json_decode($response);
|
||||
$logs = json_decode($response);
|
||||
|
||||
$this->dao->update(TABLE_COMPILE)->set('logs')->eq($response)->where('id')->eq($po->id)->exec();
|
||||
$this->dao->update(TABLE_COMPILE)->set('logs')->eq($response)->where('id')->eq($compile->id)->exec();
|
||||
}
|
||||
else
|
||||
{
|
||||
$queueInfo = json_decode($response);
|
||||
|
||||
if(!empty($queueInfo->executable))
|
||||
{
|
||||
$buildUrl = $queueInfo->executable->url . 'api/json?pretty=true';
|
||||
$buildUrl = str_replace('://', $jenkinsAuth, $buildUrl);
|
||||
|
||||
$response = common::http($buildUrl);
|
||||
$response = common::http($buildUrl);
|
||||
$buildInfo = json_decode($response);
|
||||
|
||||
if($buildInfo->building)
|
||||
{
|
||||
$this->updateBuildStatus($po, 'building');
|
||||
$this->updateBuildStatus($compile, 'building');
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = strtolower($buildInfo->result);
|
||||
$this->updateBuildStatus($po, $result);
|
||||
$this->updateBuildStatus($compile, $result);
|
||||
|
||||
$logUrl = $buildInfo->url . 'logText/progressiveText/api/json';
|
||||
$logUrl = str_replace('://', $jenkinsAuth, $logUrl);
|
||||
|
||||
$response = common::http($logUrl);
|
||||
$logs = json_decode($response);
|
||||
$logs = json_decode($response);
|
||||
|
||||
$this->dao->update(TABLE_COMPILE)->set('logs')->eq($response)->where('id')->eq($po->id)->exec();
|
||||
$this->dao->update(TABLE_COMPILE)->set('logs')->eq($response)->where('id')->eq($compile->id)->exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,24 +111,19 @@ class ciModel extends model
|
||||
public function updateBuildStatus($build, $status)
|
||||
{
|
||||
$this->dao->update(TABLE_COMPILE)->set('status')->eq($status)->where('id')->eq($build->id)->exec();
|
||||
|
||||
$this->dao->update(TABLE_INTEGRATION)
|
||||
->set('lastExec')->eq(helper::now())
|
||||
->set('lastStatus')->eq($status)
|
||||
->where('id')->eq($build->cijob)
|
||||
->exec();
|
||||
$this->dao->update(TABLE_INTEGRATION)->set('lastExec')->eq(helper::now())->set('lastStatus')->eq($status)->where('id')->eq($build->cijob)->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @return false|mixed|string
|
||||
*/
|
||||
public function sendRequest($url, $data)
|
||||
{
|
||||
if(!empty($data->PARAM_TAG)) $data->PARAM_REVISION = '';
|
||||
public function sendRequest($url, $data)
|
||||
{
|
||||
if(!empty($data->PARAM_TAG)) $data->PARAM_REVISION = '';
|
||||
|
||||
$response = common::http($url, $data, true);
|
||||
if(preg_match("!Location: .*item/(.*)/!", $response, $matches)) return $matches[1];
|
||||
return '';
|
||||
}
|
||||
$response = common::http($url, $data, true);
|
||||
if(preg_match("!Location: .*item/(.*)/!", $response, $matches)) return $matches[1];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,17 @@ class compileModel extends model
|
||||
return $this->dao->select('*')->from(TABLE_COMPILE)->where('id')->eq($buildID)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unexecuted list.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getUnexecutedList()
|
||||
{
|
||||
return $this->dao->select('*')->from(TABLE_COMPILE)->where('status')->eq('')->andWhere('deleted')->eq('0')->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save build by job
|
||||
*
|
||||
@@ -52,16 +63,91 @@ class compileModel extends model
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function saveBuild($job)
|
||||
public function createByIntegration($integrationID)
|
||||
{
|
||||
$integration = $this->dao->select('id,name')->from(TABLE_INTEGRATION)->where('id')->eq($integrationID)->fetch();
|
||||
|
||||
$build = new stdClass();
|
||||
$build->cijob = $job->jobId;
|
||||
$build->name = $job->jobName;
|
||||
$build->queueItem = $job->queueItem;
|
||||
$build->status = $job->queueItem ? 'created' : 'create_fail';
|
||||
$build->cijob = $integration->id;
|
||||
$build->name = $integration->name;
|
||||
$build->createdBy = $this->app->user->account;
|
||||
$build->createdDate = helper::now();
|
||||
|
||||
$this->dao->insert(TABLE_COMPILE)->data($build)->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute compile
|
||||
*
|
||||
* @param object $compile
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function execByCompile($compile, $data = null)
|
||||
{
|
||||
$integration = $this->dao->select('t1.id as jobId,t1.name as jobName,t1.repo,t1.jenkinsJob,t2.name as jenkinsName,t2.serviceUrl,t2.account,t2.token,t2.password')
|
||||
->from(TABLE_INTEGRATION)->alias('t1')
|
||||
->leftJoin(TABLE_JENKINS)->alias('t2')->on('t1.jenkins=t2.id')
|
||||
->where('t1.id')->eq($compile->cijob)
|
||||
->fetch();
|
||||
|
||||
if(!$integration) return false;
|
||||
|
||||
$buildUrl = $this->getBuildUrl($integration);
|
||||
$build = new stdclass();
|
||||
$build->queueItem = $this->loadModel('ci')->sendRequest($buildUrl, $data);
|
||||
$build->status = $build->queueItem ? 'created' : 'create_fail';
|
||||
$this->dao->update(TABLE_COMPILE)->data($build)->where('id')->eq($compile->id)->exec();
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute by integration.
|
||||
*
|
||||
* @param int $compile
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function execByIntegration($integrationID, $data = null)
|
||||
{
|
||||
$integration = $this->dao->select('t1.id as jobId,t1.name as jobName,t1.repo,t1.jenkinsJob,t2.name as jenkinsName,t2.serviceUrl,t2.account,t2.token,t2.password')
|
||||
->from(TABLE_INTEGRATION)->alias('t1')
|
||||
->leftJoin(TABLE_JENKINS)->alias('t2')->on('t1.jenkins=t2.id')
|
||||
->where('t1.id')->eq($integrationID)
|
||||
->fetch();
|
||||
|
||||
if(!$integration) return false;
|
||||
|
||||
$buildUrl = $this->getBuildUrl($integration);
|
||||
$build = new stdClass();
|
||||
$build->cijob = $integration->jobId;
|
||||
$build->name = $integration->jobName;
|
||||
$build->queueItem = $this->loadModel('ci')->sendRequest($buildUrl, $data);
|
||||
$build->status = $build->queueItem ? 'created' : 'create_fail';
|
||||
$build->createdBy = $this->app->user->account;
|
||||
$build->createdDate = helper::now();
|
||||
$this->dao->insert(TABLE_COMPILE)->data($build)->exec();
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get build url.
|
||||
*
|
||||
* @param object $jenkins
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getBuildUrl($jenkins)
|
||||
{
|
||||
$jenkinsServer = $jenkins->serviceUrl;
|
||||
$jenkinsUser = $jenkins->account;
|
||||
$jenkinsPassword = $jenkins->token ? $jenkins->token : base64_decode($jenkins->password);
|
||||
|
||||
$jenkinsAuth = '://' . $jenkinsUser . ':' . $jenkinsPassword . '@';
|
||||
$jenkinsServer = str_replace('://', $jenkinsAuth, $jenkinsServer);
|
||||
$buildUrl = sprintf('%s/job/%s/buildWithParameters/api/json', $jenkinsServer, $jenkins->jenkinsJob);
|
||||
return $buildUrl;
|
||||
}
|
||||
}
|
||||
|
||||
+24
-67
@@ -137,39 +137,10 @@ class gitModel extends model
|
||||
$this->printLog("\n\nrepo ' . $repo->id . ': ' . $repo->path . ' finished");
|
||||
}
|
||||
|
||||
// exe ci task from logs
|
||||
$cijobIdList = zget($objects, 'testtasks', array());
|
||||
$this->loadModel('integration');
|
||||
foreach($cijobIdList as $id) $this->integration->exec($id);
|
||||
|
||||
// dealwith tag commands
|
||||
$this->printLog("dealwith tag commands");
|
||||
$savedTag = $this->getSavedTag();
|
||||
|
||||
$tags = $this->getRepoTags($repo);
|
||||
if(!empty($tags))
|
||||
{
|
||||
$arriveLastTag = false;
|
||||
$jobToBuild = array();
|
||||
foreach($tags as $tag)
|
||||
{
|
||||
if(!empty($savedTag) && $tag === $savedTag) // get the last build tag position
|
||||
{
|
||||
$arriveLastTag = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!empty($savedTag) && !$arriveLastTag) continue;
|
||||
|
||||
$jobToBuild += $this->repo->parseTag($tag);
|
||||
}
|
||||
|
||||
$this->saveLastTag($tags[count($tags) - 1]);
|
||||
|
||||
$this->printLog('extract tasks to build: ' . json_encode($jobToBuild));
|
||||
|
||||
foreach($jobToBuild as $id) $this->integration->exec($id);
|
||||
}
|
||||
// exe ci jobs in log
|
||||
$cijobIdList = zget($objects, 'integrations', array());
|
||||
$this->loadModel('compile');
|
||||
foreach($cijobIdList as $id) $this->compile->execByIntegration($id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,26 +186,21 @@ class gitModel extends model
|
||||
*/
|
||||
public function setRepos()
|
||||
{
|
||||
$repo = $this->loadModel('repo');
|
||||
$repoObjs = $repo->listForSync("SCM='Git'");
|
||||
|
||||
$gitRepos = [];
|
||||
$paths = [];
|
||||
// ignore same repo in config.php
|
||||
foreach($repoObjs as $repoInDb)
|
||||
$repos = $this->loadModel('repo')->getListBySCM('Git');
|
||||
$gitRepos = array();
|
||||
$paths = array();
|
||||
foreach($repos as $repo)
|
||||
{
|
||||
if(strtolower($repoInDb->SCM) === 'git' && !in_array($repoInDb->path, $gitRepos)) {
|
||||
$gitRepos[] = (object)array('id'=>$repoInDb->id, 'path' => $repoInDb->path,
|
||||
'encoding' => $repoInDb->encoding, 'client' => $repoInDb->client);
|
||||
$paths[] = $repoInDb->path;
|
||||
if(strtolower($repo->SCM) == 'git' && !isset($paths[$repo->path]))
|
||||
{
|
||||
unset($repo->acl);
|
||||
unset($repo->desc);
|
||||
$gitRepos[] = $repo;
|
||||
$paths[$repo->path] = $repo->path;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$gitRepos)
|
||||
{
|
||||
echo "You must set one git repo.\n";
|
||||
return false;
|
||||
}
|
||||
if(empty($gitRepos)) echo "You must set one git repo.\n";
|
||||
|
||||
$this->repos = $gitRepos;
|
||||
return true;
|
||||
@@ -312,6 +278,7 @@ class gitModel extends model
|
||||
*/
|
||||
public function setTagFile($repoId)
|
||||
{
|
||||
$this->setLogRoot();
|
||||
$this->tagFile = $this->logRoot . $repoId . '.tag';
|
||||
}
|
||||
|
||||
@@ -336,21 +303,9 @@ class gitModel extends model
|
||||
*/
|
||||
public function getRepoTags($repo)
|
||||
{
|
||||
$parsedTags = array();
|
||||
|
||||
/* The git tag command. */
|
||||
chdir($this->repoRoot);
|
||||
exec("{$this->client} config core.quotepath false");
|
||||
|
||||
$cmd = "$this->client for-each-ref --sort=taggerdate | grep refs/tags | grep -v commit";
|
||||
exec($cmd, $list, $return);
|
||||
foreach($list as $line)
|
||||
{
|
||||
$arr = explode('refs/tags/', $line);
|
||||
$parsedTags[] = $arr[count($arr) - 1];
|
||||
}
|
||||
|
||||
return $parsedTags;
|
||||
$scm = $this->app->loadClass('scm');
|
||||
$scm->setEngine($repo);
|
||||
return $scm->tags('/');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -778,8 +733,9 @@ class gitModel extends model
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function getSavedTag()
|
||||
public function getSavedTag($repoID = 0)
|
||||
{
|
||||
if($repoID) $this->setTagFile($repoID);
|
||||
if(!file_exists($this->tagFile)) return 0;
|
||||
if(file_exists($this->restartFile)) return 0;
|
||||
return trim(file_get_contents($this->tagFile));
|
||||
@@ -792,9 +748,10 @@ class gitModel extends model
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function saveLastTag($tag)
|
||||
public function saveLastTag($tag, $repoId = 0)
|
||||
{
|
||||
$ret = file_put_contents($this->tagFile, $tag);
|
||||
if($repoId) $this->setTagFile($repoId);
|
||||
file_put_contents($this->tagFile, $tag);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -142,10 +142,6 @@ class integration extends control
|
||||
if($confirm != 'yes') die(js::confirm($this->lang->integration->confirmDelete, inlink('delete', "jobID=$id&confirm=yes")));
|
||||
|
||||
$this->integration->delete(TABLE_INTEGRATION, $id);
|
||||
|
||||
$command = 'moduleName=ci&methodName=exe&parm=' . $id;
|
||||
$this->dao->delete()->from(TABLE_CRON)->where('command')->eq($command)->exec();
|
||||
|
||||
die(js::reload('parent'));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
$lang->integration->common = '构建任务';
|
||||
$lang->integration->browse = '浏览构建任务';
|
||||
$lang->integration->create = '创建构建任务';
|
||||
$lang->integration->start = '执行构建';
|
||||
$lang->integration->edit = '编辑构建任务';
|
||||
$lang->integration->execNow = '立即执行';
|
||||
$lang->integration->delete = '删除构建任务';
|
||||
|
||||
@@ -84,6 +84,8 @@ class integrationModel extends model
|
||||
|
||||
->autoCheck()
|
||||
->exec();
|
||||
|
||||
if($integration->triggerType == 'schedule' and strpos($integration->scheduleDay, date('w')) !== false) $this->loadModel('compile')->createByIntegration($integration->id);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -96,6 +98,7 @@ class integrationModel extends model
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$oldIntegration = $this->getById($id);
|
||||
$integration = fixer::input('post')
|
||||
->add('editedBy', $this->app->user->account)
|
||||
->add('editedDate', helper::now())
|
||||
@@ -116,44 +119,15 @@ class integrationModel extends model
|
||||
->autoCheck()
|
||||
->where('id')->eq($id)
|
||||
->exec();
|
||||
|
||||
if($integration->triggerType == 'schedule')
|
||||
{
|
||||
$week = date('w');
|
||||
if($integration->triggerType != $oldIntegration->triggerType or strpos($oldIntegration->scheduleDay, $week) === false)
|
||||
{
|
||||
if(strpos($integration->scheduleDay, $week) !== false) $this->loadModel('compile')->createByIntegration($integration->id);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute integration
|
||||
*
|
||||
* @param int $integrationID
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function exec($integrationID)
|
||||
{
|
||||
$integration = $this->dao->select('t1.id as jobId,t1.name as jobName,t1.repo,t1.jenkinsJob,t2.name as jenkinsName,t2.serviceUrl,t2.account,t2.token,t2.password')
|
||||
->from(TABLE_INTEGRATION)->alias('t1')
|
||||
->leftJoin(TABLE_JENKINS)->alias('t2')->on('t1.jenkins=t2.id')
|
||||
->where('t1.id')->eq($integrationID)
|
||||
->fetch();
|
||||
|
||||
if(!$integration) return false;
|
||||
|
||||
$jenkinsServer = $integration->serviceUrl;
|
||||
$jenkinsUser = $integration->account;
|
||||
$jenkinsPassword = $integration->token ? $integration->token : base64_decode($integration->password);
|
||||
|
||||
$jenkinsAuth = '://' . $jenkinsUser . ':' . $jenkinsPassword . '@';
|
||||
$jenkinsServer = str_replace('://', $jenkinsAuth, $jenkinsServer);
|
||||
$buildUrl = sprintf('%s/job/%s/buildWithParameters/api/json', $jenkinsServer, $integration->jenkinsJob);
|
||||
|
||||
$data = new stdClass();
|
||||
// TODO: 将参数加入$data,代码完成后删除注释
|
||||
// PARAM_TAG:git tag name or svn tag url
|
||||
// PARAM_REVISION:git revision string or svn revision number
|
||||
$data->PARAM_TAG = "tag111";
|
||||
$data->PARAM_REVISION = "6c3a7bf931855842e261c7991bb143c1e0c3fb19";
|
||||
|
||||
$integration->queueItem = $this->loadModel('ci')->sendRequest($buildUrl, $data);
|
||||
$this->loadModel('compile')->saveBuild($integration);
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ $config->repo->svn->requiredFields = 'account,password';
|
||||
$config->repo->matchComment['module']['story'] = 'Story';
|
||||
$config->repo->matchComment['module']['task'] = 'Task';
|
||||
$config->repo->matchComment['module']['bug'] = 'Bug';
|
||||
$config->repo->matchComment['module']['testtask'] = 'Build';
|
||||
$config->repo->matchComment['module']['integration'] = 'Build';
|
||||
$config->repo->matchComment['task']['start'] = 'Start';
|
||||
$config->repo->matchComment['task']['finish'] = 'Finish';
|
||||
$config->repo->matchComment['task']['cancel'] = 'Cancel';
|
||||
@@ -51,7 +51,7 @@ $config->repo->matchComment['task']['consumed'] = 'Cost';
|
||||
$config->repo->matchComment['task']['left'] = 'Left';
|
||||
$config->repo->matchComment['bug']['resolve'] = 'Resolve';
|
||||
$config->repo->matchComment['bug']['resolvedBuild'] = 'Build';
|
||||
$config->repo->matchComment['testtask']['start'] = 'Start';
|
||||
$config->repo->matchComment['integration']['start'] = 'Start';
|
||||
$config->repo->matchComment['id']['mark'] = '#';
|
||||
$config->repo->matchComment['id']['split'] = ',';
|
||||
$config->repo->matchComment['mark']['consumed'] = ':';
|
||||
|
||||
@@ -590,7 +590,7 @@ class repo extends control
|
||||
$this->app->loadLang('task');
|
||||
$this->app->loadLang('bug');
|
||||
$this->app->loadLang('story');
|
||||
$this->app->loadLang('testtask');
|
||||
$this->app->loadLang('integration');
|
||||
if(is_string($this->config->repo->matchComment)) $this->config->repo->matchComment = json_decode($this->config->repo->matchComment, true);
|
||||
|
||||
$this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->setMatchComment;
|
||||
|
||||
+30
-56
@@ -178,7 +178,7 @@ class repoModel extends model
|
||||
if($data->prefix) $data->prefix = '/' . $data->prefix;
|
||||
}
|
||||
|
||||
$data->password = base64_encode($data->password);
|
||||
if($data->encrypt == 'base64') $data->password = base64_encode($data->password);
|
||||
$this->dao->insert(TABLE_REPO)->data($data)
|
||||
->batchCheck($this->config->repo->create->requiredFields, 'notempty')
|
||||
->checkIF($data->SCM == 'Subversion', $this->config->repo->svn->requiredFields, 'notempty')
|
||||
@@ -236,7 +236,7 @@ class repoModel extends model
|
||||
|
||||
if($data->path != $repo->path) $data->synced = 0;
|
||||
|
||||
$data->password = base64_encode($data->password);
|
||||
if($data->encrypt == 'base64') $data->password = base64_encode($data->password);
|
||||
$this->dao->update(TABLE_REPO)->data($data)
|
||||
->batchCheck($this->config->repo->edit->requiredFields, 'notempty')
|
||||
->checkIF($data->SCM == 'Subversion', $this->config->repo->svn->requiredFields, 'notempty')
|
||||
@@ -284,11 +284,23 @@ class repoModel extends model
|
||||
$repo = $this->dao->select('*')->from(TABLE_REPO)->where('id')->eq($repoID)->fetch();
|
||||
if(!$repo) return false;
|
||||
|
||||
$repo->password = base64_decode($repo->password);
|
||||
if($repo->encrypt == 'base64') $repo->password = base64_decode($repo->password);
|
||||
$repo->acl = json_decode($repo->acl);
|
||||
return $repo;
|
||||
}
|
||||
|
||||
public function getByIdList($idList)
|
||||
{
|
||||
$repos = $this->dao->select('*')->from(TABLE_REPO)->where('deleted')->eq(0)->andWhere('id')->in($idList)->fetchAll();
|
||||
foreach($repos as $i => $repo)
|
||||
{
|
||||
if($repo->encrypt == 'base64') $repo->password = base64_decode($repo->password);
|
||||
$repo->acl = json_decode($repo->acl);
|
||||
}
|
||||
|
||||
return $repos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get git branches.
|
||||
*
|
||||
@@ -921,17 +933,16 @@ class repoModel extends model
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function listForSync($whr)
|
||||
public function getListBySCM($scm)
|
||||
{
|
||||
$repos = $this->dao->select('*')->from(TABLE_REPO)
|
||||
->where('deleted')->eq('0')
|
||||
->beginIF(!empty($whr))->andWhere('(' . $whr . ')')->fi()
|
||||
$repos = $this->dao->select('*')->from(TABLE_REPO)->where('deleted')->eq('0')
|
||||
->andWhere('SCM')->eq($scm)
|
||||
->orderBy('id')
|
||||
->fetchAll();
|
||||
|
||||
foreach($repos as $repo)
|
||||
{
|
||||
$repo->password = base64_decode($repo->password);
|
||||
if($repo->encrypt == 'base64') $repo->password = base64_decode($repo->password);
|
||||
}
|
||||
|
||||
return $repos;
|
||||
@@ -949,12 +960,12 @@ class repoModel extends model
|
||||
if(is_string($this->config->repo->matchComment)) $this->config->repo->matchComment = json_decode($this->config->repo->matchComment, true);
|
||||
$matchComment = $this->config->repo->matchComment;
|
||||
|
||||
$matches = array();
|
||||
$stories = array();
|
||||
$tasks = array();
|
||||
$bugs = array();
|
||||
$testtasks = array();
|
||||
$actions = array();
|
||||
$matches = array();
|
||||
$stories = array();
|
||||
$tasks = array();
|
||||
$bugs = array();
|
||||
$integrations = array();
|
||||
$actions = array();
|
||||
while(true)
|
||||
{
|
||||
$found = preg_match("/{$matchComment['id']['mark']}[0-9]+({$matchComment['id']['split']}[0-9]+)*/", $comment, $matches);
|
||||
@@ -1017,14 +1028,14 @@ class repoModel extends model
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($module == 'testtask')
|
||||
elseif($module == 'integration')
|
||||
{
|
||||
foreach($idList as $id) $testtasks[$id] = $id;
|
||||
foreach($matchComment['testtask'] as $method => $match)
|
||||
foreach($idList as $id) $integrations[$id] = $id;
|
||||
foreach($matchComment['integration'] as $method => $match)
|
||||
{
|
||||
if(strpos($subComment, $match) !== false)
|
||||
{
|
||||
foreach($idList as $id) $actions['testtask'][$id]['action'] = $method;
|
||||
foreach($idList as $id) $actions['integration'][$id]['action'] = $method;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1033,44 +1044,7 @@ class repoModel extends model
|
||||
}
|
||||
}
|
||||
|
||||
return array('stories' => $stories, 'tasks' => $tasks, 'bugs' => $bugs, 'testtasks' => $testtasks, 'actions' => $actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the tag, extract task list from it.
|
||||
*
|
||||
* @param string $comment
|
||||
* @access public
|
||||
*/
|
||||
public function parseTag($comment)
|
||||
{
|
||||
global $config;
|
||||
if(is_string($config->repo->matchComment)) $config->repo->matchComment = json_decode($config->repo->matchComment, true);
|
||||
$matchComment = $config->repo->matchComment;
|
||||
|
||||
$testtasks = array();
|
||||
while(true)
|
||||
{
|
||||
$found = preg_match("/{$matchComment['id']['mark']}[0-9]+({$matchComment['id']['split']}[0-9]+)*/", $comment, $matches);
|
||||
if(empty($found)) break;
|
||||
if($found)
|
||||
{
|
||||
$position = strpos($comment, $matches[0]);
|
||||
$subComment = substr($comment, 0, $position + strlen($matches[0]));
|
||||
$comment = substr($comment, $position + strlen($matches[0]) + 1);
|
||||
|
||||
$idList = explode($matchComment['id']['mark'], str_replace($matchComment['id']['split'], '', $matches[0]));
|
||||
foreach($matchComment['module'] as $module => $moduleMatch)
|
||||
{
|
||||
if($module != 'testtask') continue;
|
||||
if(stripos($subComment, $moduleMatch) !== false)
|
||||
{
|
||||
foreach($idList as $id) $testtasks[$id] = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $testtasks;
|
||||
return array('stories' => $stories, 'tasks' => $tasks, 'bugs' => $bugs, 'integrations' => $integrations, 'actions' => $actions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -52,12 +52,12 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $lang->testtask->common;?></th>
|
||||
<th><?php echo $lang->integration->common;?></th>
|
||||
<td>
|
||||
<div class='input-group'>
|
||||
<?php foreach($config->repo->matchComment['testtask'] as $method => $match):?>
|
||||
<span class='input-group-addon'><?php echo $lang->testtask->$method;?></span>
|
||||
<?php echo html::input("matchComment[testtask][{$method}]", $match, "class='form-control'");?>
|
||||
<?php foreach($config->repo->matchComment['integration'] as $method => $match):?>
|
||||
<span class='input-group-addon'><?php echo $lang->integration->$method;?></span>
|
||||
<?php echo html::input("matchComment[integration][{$method}]", $match, "class='form-control'");?>
|
||||
<?php endforeach;?>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
+36
-68
@@ -139,31 +139,9 @@ class svnModel extends model
|
||||
}
|
||||
|
||||
// exe ci jobs in log
|
||||
$cijobIdList = zget($objects, 'testtasks', array());
|
||||
$this->loadModel('integration');
|
||||
foreach($cijobIdList as $id) $this->integration->exec($id);
|
||||
|
||||
// dealwith tag commands
|
||||
$this->printLog("dealwith tag commands");
|
||||
$savedTags = $this->getSavedTags($repo->id);
|
||||
|
||||
$tags = $this->getRepoTags($repo);
|
||||
if(!empty($tags))
|
||||
{
|
||||
$jobToBuild = array();
|
||||
foreach($tags as $tag)
|
||||
{
|
||||
if($savedTags[$tag]) continue;
|
||||
|
||||
$jobToBuild += $this->repo->parseTag($tag);
|
||||
|
||||
$this->saveLastTag($tag, $repo->id);
|
||||
}
|
||||
$this->printLog('extract tasks to build: ' . json_encode($jobToBuild));
|
||||
|
||||
// exe ci jobs in tag
|
||||
foreach($jobToBuild as $id) $this->integration->exec($id);
|
||||
}
|
||||
$cijobIdList = zget($objects, 'integrations', array());
|
||||
$this->loadModel('compile');
|
||||
foreach($cijobIdList as $id) $this->compile->execByCompile($id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,6 +157,12 @@ class svnModel extends model
|
||||
if(!is_dir($this->logRoot)) mkdir($this->logRoot);
|
||||
}
|
||||
|
||||
public function setTagFile($repoId)
|
||||
{
|
||||
$this->setLogRoot();
|
||||
$this->tagFile = $this->logRoot . $repoId . '.tag';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the restart file.
|
||||
*
|
||||
@@ -209,27 +193,23 @@ class svnModel extends model
|
||||
*/
|
||||
public function setRepos()
|
||||
{
|
||||
$repo = $this->loadModel('repo');
|
||||
$repoObjs = $repo->listForSync("SCM='Subversion'");
|
||||
$repos = $this->loadModel('repo')->getListBySCM('Subversion');
|
||||
|
||||
$svnRepos = [];
|
||||
$paths = [];
|
||||
// ignore same repo in config.php
|
||||
foreach($repoObjs as $repoInDb)
|
||||
$svnRepos = array();
|
||||
$paths = array();
|
||||
|
||||
foreach($repos as $repo)
|
||||
{
|
||||
if(strtolower($repoInDb->SCM) === 'subversion' && !in_array($repoInDb->path, $svnRepos)) {
|
||||
$svnRepos[] = (object)array('id'=>$repoInDb->id, 'path' => $repoInDb->path,
|
||||
'encoding' => $repoInDb->encoding, 'client' => $repoInDb->client, 'account' => $repoInDb->account, 'password' => $repoInDb->password);
|
||||
$paths[] = $repoInDb->path;
|
||||
if(strtolower($repo->SCM) === 'subversion' && !isset($paths[$repo->path]))
|
||||
{
|
||||
unset($repo->acl);
|
||||
unset($repo->desc);
|
||||
$svnRepos[] = $repo;
|
||||
$paths[$repo->path] = $repo->path;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$svnRepos)
|
||||
{
|
||||
echo "You must set one svn repo.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(empty($svnRepos)) echo "You must set one svn repo.\n";
|
||||
$this->repos = $svnRepos;
|
||||
return true;
|
||||
}
|
||||
@@ -341,26 +321,11 @@ class svnModel extends model
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getRepoTags($repo)
|
||||
public function getRepoTags($repo, $path)
|
||||
{
|
||||
$path = $repo->path;
|
||||
if (substr($path, -1) != '/') $path .= '/';
|
||||
|
||||
$path = str_replace("/trunk/","/tags/", $path);
|
||||
|
||||
$parsedTags = array();
|
||||
|
||||
chdir($this->repoRoot);
|
||||
$cmd = "$this->client ls $path";
|
||||
exec($cmd, $list, $return);
|
||||
foreach($list as $line)
|
||||
{
|
||||
if (substr($path, -1) == '/') $line = substr($line, 0, strlen($line) - 1);
|
||||
|
||||
$parsedTags[] = $line;
|
||||
}
|
||||
|
||||
return $parsedTags;
|
||||
$scm = $this->app->loadClass('scm');
|
||||
$scm->setEngine($repo);
|
||||
return $scm->tags($path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -767,9 +732,14 @@ class svnModel extends model
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function getSavedTags($repoId)
|
||||
public function getSavedTag($repoID = 0)
|
||||
{
|
||||
$tags = $this->dao->select('name, id')->from(TABLE_TAG)->where('repo')->eq($repoId)->fetchPairs();
|
||||
if($repoID) $this->setTagFile($repoID);
|
||||
if(!file_exists($this->tagFile)) return array();
|
||||
if(file_exists($this->restartFile)) return array();
|
||||
|
||||
$tags = array();
|
||||
foreach(json_decode(file_get_contents($this->tagFile)), $tag) $tags[$tag] = $tag;
|
||||
return $tags;
|
||||
}
|
||||
|
||||
@@ -780,12 +750,10 @@ class svnModel extends model
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function saveLastTag($tag, $repoId)
|
||||
public function saveLastTag($tag, $repoId = 0)
|
||||
{
|
||||
$data = (object) array('name'=>$tag, 'repo'=>$repoId);
|
||||
|
||||
$ret = $this->dao->insert(TABLE_TAG)->data($data)
|
||||
->batchCheck($this->config->svn->tagRequiredFields, 'notempty')
|
||||
->autoCheck()->exec();
|
||||
if($repoId) $this->setTagFile($repoId);
|
||||
if(is_array($tag)) $tag = json_encode($tag);
|
||||
file_put_contents($this->tagFile, $tag);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user