* finish task #6856.

This commit is contained in:
wangyidong
2020-02-21 12:27:05 +08:00
parent c99bc8209e
commit c001e75780
10 changed files with 104 additions and 17 deletions
+6
View File
@@ -66,3 +66,9 @@ INSERT INTO `zt_cron` (`m`, `h`, `dom`, `mon`, `dow`, `command`, `remark`, `type
ALTER TABLE `zt_cibuild` RENAME TO `zt_compile`;
ALTER TABLE `zt_cijob` RENAME TO `zt_integration`;
ALTER TABLE `zt_integration`
DROP `scheduleType`,
DROP `cronExpression`,
DROP `scheduleTime`,
DROP `scheduleInterval`;
+11 -11
View File
@@ -31,14 +31,14 @@ class ciModel extends model
*/
public function checkBuildStatus()
{
$pos = $this->dao->select('build.*, job.jenkinsJob, jenkins.name jenkinsName,jenkins.serviceUrl,jenkins.account,jenkins.token,jenkins.password')
->from(TABLE_COMPILE)->alias('build')
->leftJoin(TABLE_INTEGRATION)->alias('job')->on('build.cijob=job.id')
->leftJoin(TABLE_JENKINS)->alias('jenkins')->on('job.jenkins=jenkins.id')
->where('build.status')->ne('success')
->andWhere('build.status')->ne('fail')
->andWhere('build.status')->ne('timeout')
->andWhere('build.createdDate')->gt(date(DT_DATETIME1, strtotime("-1 day")))
$pos = $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')
->where('t1.status')->ne('success')
->andWhere('t1.status')->ne('fail')
->andWhere('t1.status')->ne('timeout')
->andWhere('t1.createdDate')->gt(date(DT_DATETIME1, strtotime("-1 day")))
->fetchAll();
foreach($pos as $po)
@@ -47,7 +47,7 @@ class ciModel extends model
$jenkinsUser = $po->account;
$jenkinsPassword = $po->token ? $po->token : base64_decode($po->password);
$jenkinsAuth = '://' . $jenkinsUser . ':' . $jenkinsTokenOrPassword . '@';
$jenkinsAuth = '://' . $jenkinsUser . ':' . $jenkinsPassword . '@';
$jenkinsServer = str_replace('://', $jenkinsAuth, $jenkinsServer);
$queueUrl = sprintf('%s/queue/item/%s/api/json', $jenkinsServer, $po->queueItem);
@@ -73,7 +73,7 @@ class ciModel extends model
if(!empty($queueInfo->executable))
{
$buildUrl = $queueInfo->executable->url . 'api/json?pretty=true';
$buildUrl = str_replace('://', $r, $buildUrl);
$buildUrl = str_replace('://', $jenkinsAuth, $buildUrl);
$response = common::http($buildUrl);
$buildInfo = json_decode($response);
@@ -88,7 +88,7 @@ class ciModel extends model
$this->updateBuildStatus($po, $result);
$logUrl = $buildInfo->url . 'logText/progressiveText/api/json';
$logUrl = str_replace('://', $r, $logUrl);
$logUrl = str_replace('://', $jenkinsAuth, $logUrl);
$response = common::http($logUrl);
$logs = json_decode($response);
+1
View File
@@ -125,6 +125,7 @@ class integration extends control
$this->view->repoTypes = $repoTypes;
$this->view->job = $job;
$this->view->jenkinsList = $this->loadModel('jenkins')->getPairs();
$this->view->jenkinsJobs = $this->jenkins->getTasks($job->jenkins);
$this->display();
}
+18
View File
@@ -84,6 +84,24 @@ $('#triggerType').change(function()
}
});
$('#jenkins').change(function()
{
var jenkinsID = $(this).val();
$('#jenkinsJobBox').html("<div class='load-indicator loading'></div>");
$.getJSON(createLink('jenkins', 'ajaxGetTasks', 'jenkinsID=' + jenkinsID), function(tasks)
{
html = "<select id='jenkinsJob' name='jenkinsJob' class='form-control'>";
for(taskKey in tasks)
{
var task = tasks[taskKey];
html += "<option value='" + taskKey + "'>" + task + "</option>";
}
html += '</select>';
$('#jenkinsJobBox').html(html);
$('#jenkinsJobBox #jenkinsJob').chosen();
})
})
$(function()
{
$('#repo').change();
+18
View File
@@ -86,6 +86,24 @@ $('#triggerType').change(function()
}
});
$('#jenkins').change(function()
{
var jenkinsID = $(this).val();
$('#jenkinsJobBox').html("<div class='load-indicator loading'></div>");
$.getJSON(createLink('jenkins', 'ajaxGetTasks', 'jenkinsID=' + jenkinsID), function(tasks)
{
html = "<select id='jenkinsJob' name='jenkinsJob' class='form-control'>";
for(taskKey in tasks)
{
var task = tasks[taskKey];
html += "<option value='" + taskKey + "'>" + task + "</option>";
}
html += '</select>';
$('#jenkinsJobBox').html(html);
$('#jenkinsJobBox #jenkinsJob').chosen();
})
})
$(function()
{
$('#repo').change();
+1 -1
View File
@@ -44,7 +44,7 @@
<?php $triggerType = zget($lang->integration->triggerTypeList, $job->triggerType);?>
<td class='text' title='<?php echo $triggerType;?>'><?php echo $triggerType;?></td>
<td class='text' title='<?php echo $job->jenkinsName; ?>'><?php echo $job->jenkinsName; ?></td>
<td class='text' title='<?php echo $job->jenkinsJob; ?>'><?php echo $job->jenkinsJob; ?></td>
<td class='text' title='<?php echo $job->jenkinsJob; ?>'><?php echo urldecode($job->jenkinsJob);?></td>
<td class='text'><?php if($job->lastStatus) echo zget($lang->compile->statusList, $job->lastStatus) . $lang->ci->at . $job->lastExec;?></td>
<td class='c-actions text-center'>
<?php
+1 -1
View File
@@ -38,7 +38,7 @@
<th><?php echo $lang->integration->jenkins; ?></th>
<td><?php echo html::select('jenkins', $jenkinsList, '', "class='form-control chosen'"); ?></td>
<th><?php echo $lang->integration->jenkinsJob; ?></th>
<td><?php echo html::input('jenkinsJob', '', "class='form-control'"); ?></td>
<td id='jenkinsJobBox'><?php echo html::select('jenkinsJob', array('' => ''), '', "class='form-control chosen'"); ?></td>
</tr>
<tr>
<th><?php echo $lang->integration->triggerType; ?></th>
+2 -1
View File
@@ -17,6 +17,7 @@
<?php js::set('jobRepo', $job->repo);?>
<?php js::set('svnFolder', $job->svnFolder);?>
<?php js::set('encodeSVNFolder', $this->loadModel('repo')->encodePath($job->svnFolder));?>
<?php js::set('jenkinsJob', $job->jenkinsJob);?>
<div id='mainContent' class='main-row'>
<div class='main-content'>
@@ -41,7 +42,7 @@
<th><?php echo $lang->integration->jenkins; ?></th>
<td><?php echo html::select('jenkins', $jenkinsList, $job->jenkins, "class='form-control chosen'"); ?></td>
<th><?php echo $lang->integration->jenkinsJob; ?></th>
<td><?php echo html::input('jenkinsJob', $job->jenkinsJob, "class='form-control'"); ?></td>
<td id='jenkinsJobBox'><?php echo html::select('jenkinsJob', $jenkinsJobs, $job->jenkinsJob, "class='form-control chosen'");?></td>
</tr>
<tr>
<th><?php echo $lang->integration->triggerType; ?></th>
+13
View File
@@ -117,4 +117,17 @@ class jenkins extends control
$this->jenkins->delete(TABLE_JENKINS, $id);
die(js::reload('parent'));
}
/**
* Ajax get tasks.
*
* @param int $id
* @access public
* @return void
*/
public function ajaxGetTasks($id)
{
$tasks = $this->jenkins->getTasks($id);
die(json_encode($tasks));
}
}
+33 -3
View File
@@ -101,8 +101,38 @@ class jenkinsModel extends model
*/
public function getPairs()
{
$repos = $this->dao->select('id,name')->from(TABLE_JENKINS)->where('deleted')->eq('0')->orderBy('id')->fetchPairs('id', 'name');
$repos = array('' => '') + $repos;
return $repos;
$jenkins = $this->dao->select('id,name')->from(TABLE_JENKINS)->where('deleted')->eq('0')->orderBy('id')->fetchPairs('id', 'name');
$jenkins = array('' => '') + $jenkins;
return $jenkins;
}
/**
* Get jenkins tasks.
*
* @param int $id
* @access public
* @return array
*/
public function getTasks($id)
{
$jenkins = $this->getById($id);
$jenkinsServer = $jenkins->serviceUrl;
$jenkinsUser = $jenkins->account;
$jenkinsPassword = $jenkins->token ? $jenkins->token : $jenkins->password;
$jenkinsAuth = '://' . $jenkinsUser . ':' . $jenkinsPassword . '@';
$jenkinsServer = str_replace('://', $jenkinsAuth, $jenkinsServer);
$response = common::http($jenkinsServer . '/api/json/items/list');
$response = json_decode($response);
$tasks = array();
if(isset($response->jobs))
{
foreach($response->jobs as $job) $tasks[basename($job->url)] = $job->name;
}
return $tasks;
}
}