From 933ebacfb5b18927cbe2b1a81bcdd6cab16a2368 Mon Sep 17 00:00:00 2001 From: aaronchen2k <462826@qq.com> Date: Wed, 15 Jan 2020 13:43:10 +0800 Subject: [PATCH] add job into zt_cron table to check citask status every 5 mins --- bin/init.sh | 12 +------ db/update12.1.sql | 80 +++++++++++++++++++++++++++++++++++++++++++ db/zentao.sql | 80 +------------------------------------------ module/ci/control.php | 30 ++++++++-------- 4 files changed, 97 insertions(+), 105 deletions(-) create mode 100644 db/update12.1.sql diff --git a/bin/init.sh b/bin/init.sh index 344f7bc484..ef486e90c3 100755 --- a/bin/init.sh +++ b/bin/init.sh @@ -131,17 +131,8 @@ fi echo $deletelog > $basePath/deletelog.sh echo "deletelog.sh ok" -# check jenkins task status. -if [ $requestType == 'PATH_INFO' ]; then - checkCibuild="$phpcli $basePath/ztcli '$pmsRoot/ci-checkCibuild'"; -else - checkCibuild="$phpcli $basePath/ztcli '$pmsRoot/index.php?m=ci&f=checkCibuild'"; -fi -echo $checkCibuild > $basePath/checkcibuild.sh -echo "checkcibuild.sh ok" - # cron -if [ ! -d "$basePath/cron" ]; then +if [ ! -d "$basePath/cron" ]; then mkdir $basePath/cron fi echo "# system cron." > $basePath/cron/sys.cron @@ -155,7 +146,6 @@ echo "1-59/5 * * * * $basePath/sendmail.sh # async send mail echo "1-59/5 * * * * $basePath/sendwebhook.sh # async send webhook." >> $basePath/cron/sys.cron echo "1 1 * * * $basePath/createcycle.sh # create cycle todo." >> $basePath/cron/sys.cron echo "30 1 * * * $basePath/deletelog.sh # delete log." >> $basePath/cron/sys.cron -echo "1-59/3 * * * * $basePath/checkcibuild.sh # check ci build status." >> $basePath/cron/sys.cron cron="$phpcli $basePath/php/crond.php" echo $cron > $basePath/cron.sh echo "cron.sh ok" diff --git a/db/update12.1.sql b/db/update12.1.sql new file mode 100644 index 0000000000..43f82455d3 --- /dev/null +++ b/db/update12.1.sql @@ -0,0 +1,80 @@ + +ALTER TABLE `zt_repo` +ADD COLUMN `credential` MEDIUMINT(8) NULL AFTER `password`; +ALTER TABLE `zt_repo` +ADD COLUMN `desc` TEXT NULL AFTER `lastSync`; + +CREATE TABLE `zt_credentials` ( + `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `type` varchar(10) NOT NULL DEFAULT 'account', + `name` varchar(50) NOT NULL, + `username` varchar(255) DEFAULT NULL, + `password` varchar(255) DEFAULT NULL, + `publicKey` text, + `privateKey` text, + `passphrase` varchar(20) DEFAULT NULL, + `desc` text NOT NULL, + `createdBy` varchar(30) NOT NULL, + `createdDate` datetime NOT NULL, + `editedBy` varchar(30) NOT NULL, + `editedDate` datetime NOT NULL, + `deleted` enum('0','1') NOT NULL DEFAULT '0', + `token` varchar(500) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8; + +CREATE TABLE `zt_jenkins` ( + `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `username` varchar(255) DEFAULT NULL, + `serviceUrl` varchar(255) DEFAULT NULL, + `token` varchar(255) DEFAULT NULL, + `desc` text NOT NULL, + `createdBy` varchar(30) NOT NULL, + `createdDate` datetime NOT NULL, + `editedBy` varchar(30) NOT NULL, + `editedDate` datetime NOT NULL, + `deleted` enum('0','1') NOT NULL DEFAULT '0', + `credential` mediumint(8) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=utf8; + +CREATE TABLE `zt_citask` ( + `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `repo` mediumint(8) unsigned NOT NULL, + `jenkins` mediumint(8) unsigned NOT NULL, + `jenkinsTask` varchar(500) NOT NULL, + `buildType` varchar(255) NOT NULL, + `triggerType` varchar(255) NOT NULL, + `scheduleType` varchar(255) NOT NULL, + `cornExpression` varchar(255) DEFAULT NULL, + `scheduleDay` varchar(255) DEFAULT NULL, + `scheduleTime` varchar(255) DEFAULT NULL, + `scheduleInterval` mediumint(8) DEFAULT NULL, + `tagKeywords` varchar(255) DEFAULT NULL, + `commentKeywords` varchar(255) DEFAULT NULL, + `desc` text, + `createdBy` varchar(30) NOT NULL, + `createdDate` datetime NOT NULL, + `editedBy` varchar(30) NOT NULL, + `editedDate` datetime NOT NULL, + `deleted` enum('0','1') NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=17 DEFAULT CHARSET=utf8; + +CREATE TABLE `zt_cibuild` ( + `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `citask` mediumint(8) unsigned NOT NULL, + `status` varchar(255) NOT NULL, + `logs` text, + `createdBy` varchar(30) NOT NULL, + `createdDate` datetime NOT NULL, + `updateDate` datetime NOT NULL, + `deleted` enum('0','1') NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=utf8; + +INSERT INTO `zt_cron` (`m`, `h`, `dom`, `mon`, `dow`, `command`, `remark`, `type`, `buildin`, `status`, `lastTime`) VALUES +('*/5', '*', '*', '*', '*', 'moduleName=ci&methodName=checkCibuild', '同步Jenkins任务状态', 'zentao', 0, 'stop', '0000-00-00 00:00:00'); diff --git a/db/zentao.sql b/db/zentao.sql index 9f513dc260..ddfee79f63 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -3450,82 +3450,4 @@ INSERT INTO `zt_grouppriv` (`group`, `module`, `method`) VALUES (11, 'user', 'testTask'), (11, 'user', 'todo'), (11, 'user', 'view'), -(12, 'my', 'limited'); - -ALTER TABLE `zentao_zhonghe`.`zt_repo` -ADD COLUMN `credential` MEDIUMINT(8) NULL AFTER `password`; -ALTER TABLE `zentao_zhonghe`.`zt_repo` -ADD COLUMN `desc` TEXT NULL AFTER `lastSync`; - -CREATE TABLE `zt_credentials` ( - `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, - `type` varchar(10) NOT NULL DEFAULT 'account', - `name` varchar(50) NOT NULL, - `username` varchar(255) DEFAULT NULL, - `password` varchar(255) DEFAULT NULL, - `publicKey` text, - `privateKey` text, - `passphrase` varchar(20) DEFAULT NULL, - `desc` text NOT NULL, - `createdBy` varchar(30) NOT NULL, - `createdDate` datetime NOT NULL, - `editedBy` varchar(30) NOT NULL, - `editedDate` datetime NOT NULL, - `deleted` enum('0','1') NOT NULL DEFAULT '0', - `token` varchar(500) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8; - -CREATE TABLE `zt_jenkins` ( - `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(50) NOT NULL, - `username` varchar(255) DEFAULT NULL, - `serviceUrl` varchar(255) DEFAULT NULL, - `token` varchar(255) DEFAULT NULL, - `desc` text NOT NULL, - `createdBy` varchar(30) NOT NULL, - `createdDate` datetime NOT NULL, - `editedBy` varchar(30) NOT NULL, - `editedDate` datetime NOT NULL, - `deleted` enum('0','1') NOT NULL DEFAULT '0', - `credential` mediumint(8) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=utf8; - -CREATE TABLE `zt_citask` ( - `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(50) NOT NULL, - `repo` mediumint(8) unsigned NOT NULL, - `jenkins` mediumint(8) unsigned NOT NULL, - `jenkinsTask` varchar(500) NOT NULL, - `buildType` varchar(255) NOT NULL, - `triggerType` varchar(255) NOT NULL, - `scheduleType` varchar(255) NOT NULL, - `cornExpression` varchar(255) DEFAULT NULL, - `scheduleDay` varchar(255) DEFAULT NULL, - `scheduleTime` varchar(255) DEFAULT NULL, - `scheduleInterval` mediumint(8) DEFAULT NULL, - `tagKeywords` varchar(255) DEFAULT NULL, - `commentKeywords` varchar(255) DEFAULT NULL, - `desc` text, - `createdBy` varchar(30) NOT NULL, - `createdDate` datetime NOT NULL, - `editedBy` varchar(30) NOT NULL, - `editedDate` datetime NOT NULL, - `deleted` enum('0','1') NOT NULL DEFAULT '0', - PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=17 DEFAULT CHARSET=utf8; - -CREATE TABLE `zt_cibuild` ( - `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(50) NOT NULL, - `citask` mediumint(8) unsigned NOT NULL, - `status` varchar(255) NOT NULL, - `logs` text, - `createdBy` varchar(30) NOT NULL, - `createdDate` datetime NOT NULL, - `updateDate` datetime NOT NULL, - `deleted` enum('0','1') NOT NULL DEFAULT '0', - PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=utf8; - +(12, 'my', 'limited'); \ No newline at end of file diff --git a/module/ci/control.php b/module/ci/control.php index 1d76315344..36276370b0 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -474,6 +474,21 @@ class ci extends control $this->send(array('result' => 'success')); } + /** + * sync repo from remote. + * + * @param int $repoID + * @access public + * @return void + */ + public function syncRepo($repoID = 0) + { + $this->dao->update(TABLE_REPO)->set('synced')->eq(0)->where('id')->eq($repoID)->exec(); + + $link = $this->ci->createLink('showSyncComment', "repoID=$repoID&needPull=true"); + $this->send(array('result' => 'success', 'locate' => $link)); + } + /** * browse branches. * @@ -493,21 +508,6 @@ class ci extends control $this->display(); } - /** - * sync repo from remote. - * - * @param int $repoID - * @access public - * @return void - */ - public function syncRepo($repoID = 0) - { - $this->dao->update(TABLE_REPO)->set('synced')->eq(0)->where('id')->eq($repoID)->exec(); - - $link = $this->ci->createLink('showSyncComment', "repoID=$repoID&needPull=true"); - $this->send(array('result' => 'success', 'locate' => $link)); - } - /** * watch branch. *