CIZE 是一个「持续集成」工具,但愿能让开发人员更快捷的搭建一个完整、可靠、便捷的 CI 服务。
甚至能够像 Gulp 或 Grunt 同样,仅仅经过一个 cizefile.js
便可完成几乎全部的工做。git
若是您对它有一点兴趣,欢迎到 GitHub 加个 star 以关注它。
https://github.com/Houfeng/cizegithub
$ [sudo] npm install cize -g
新建 cizefile.jsshell
$ mkdir your_path $ cd your_path $ vim cizefile.js
输入以下内容npm
//定义「项目」 const demo = cize.project('demo', {}); //定义一个 Job,这是一个最基础的 Job demo.job('hello', function (self) { self.console.log('hello world'); self.done(); });
而后,在「工做目录」中执行 cize
启动服务vim
$ cize Strarting... The server on "localhost:9000" started
默认会启动和 CPU 核数相同的「工做进程」。浏览器
接下来,能够在浏览器中访问 http://localhost:9000
,
并能够在 UI 中手动触发这个名为 hello
的 Job工具
const demo = cize.project('demo', { ... //能够在此添加针对项目的配置 ... });
注意,即使一个项目不须要任何配置,也不能省略第二个参数,
没有第二个参数时 cize.project(name)
为获取指定的项目gitlab
假定如今已经有一个定义好的名为 demo
的 project
ui
demo.job('test', function (self) { self.console.log('test'); self.done(); });
这是最基础的 Job 类型,是其它 Job 类型或「扩展」的基础。命令行
demo.job('test', cize.shell(function () { /* echo "hello world" */ }));
定义一个用 SHELL 编写的 Job,用到了 cize.shell,这是一个「内置扩展」
demo.job('test', cize.cron('* */2 * * * *', cize.shell(function () { /* echo "hello world" */ })));
如上定义了一个每两分种触发一次的 Job 而且,嵌套使用了 shell.
demo.job('test2', cize.by('test1', function(self){ self.console.log('hello'); self.done(); });
以下,在 test1 执行成功后,将会触发 test2
demo.job('test', cize.series([ "test1", function(self){ self.console.log('hello'); self.done(); }, "test3" ]));
series 是一个内置扩展,能够定义一个「串行执行」多个步骤的任务列表,每一个步骤能够是一个任意类型的 job,
也能够是指定要调用的其它 Job 的名称。
demo.job('test', cize.parallel([ "test1", function(self){ self.console.log('hello'); self.done(); }, "test3" ]));
series 是一个内置扩展,能够定义一个「并行执行」多个步骤的任务列表,每一个步骤能够是一个任意类型的 job,
也能够是指定要调用的其它 Job 的名称。
CIZE 全部的 Job 能够自由嵌套,例如:
demo.job('test', cize.parallel([ "test1", function(self){ self.console.log('hello'); self.done(); }, "test3", cize.series([ "test4", cize.shell(function(){ /* echo hello */ }) ]) ]));
当你使用一个「外部扩展」时,也能够混合使用。
如上用到的 cize.shell、cize.series、cize。parallel、cize.cron、cize.by 是 cize 默契认包含的「内置扩展」。
编写一个「外部扩展」和「内置扩展」并没有本质区别,以下:
module.exports = function(options...){ return function(self){ //处理逻辑 }; };
如查须要在 Job 定义时进行一些处理,能够使用 register
,以下
module.exports = function(options...){ return { register: function(Job){ //Job 是你的「自定义 Job 类型」 //注册时逻辑 }, runable: function(self){ //执行时逻辑 } }; };
能够将扩展发布为一个「npm 包」,让更多的人使用。
能够经过一些选择去控制 CI 服务的端口、密钥等,有两种方式,以下
cize.config({ port: 9000, secret: '12345' });
cize ./ -p=port -s=secret
经过 cize -h 能够查看完整的说明
Usage: cize [folder|file] [options] Options: -w set the number of workers -p set the port -s set the secret -h display help information Example: cize ./ -p=9000 -s=12345 -w=4
请访问 wiki: https://github.com/Houfeng/cize/wiki
若是您对它有一点问题或建议,请到 GitHub 经过 issue 提出您的疑问或建议。https://github.com/Houfeng/cize-gitlab/issues