1gittlab,配置本地Git.
2 添加项目到CI(Continues Integration)中
ci-01.png
3 单击项目,进入CI页面中
第一次没有配置的情况下:
ci-02.png
4 添加".gitlab-ci.yml"文件
".gitlab-ci.yml"文件放在仓库的根目录下,用来设置gitlab项目的runner,每次在push的时候自动触发项目的build。
首先在项目的根目录下(git clone ...)创建'.gitlab-ci.yml'文件,针对新建的示例项目创建简单的内容:
文件包含多个stage,如build、test、deploy,每个相同的stage运行都是并行的,而后面的stage必须在前面的stage运行结束才能开始。script表示运行命令,示例中以shell命令为例。tags表示runner的标签,用哪个runner来build项目,关于runner的配置在下一章中。
另外,在build完项目后,可以添加一个脚本用来进行测试程序,如'-bash scripts'。
添加文件"hello.cpp"和".gitlab-ci.yml",然后push到gitlab。
成功之后,commit的状态为"pending",意思是正在等待中,因为还没有runner来执行。
转存失败重新上传取消
image
关于文件格式内容的详细说明.gitlab-ci.yml
5 配置Runner
单击网页左侧Runners。
ci-03.png
有"Specific runners"和"Shared runners"两种,我们只介绍"Specific runners"的配置,关于runner的详细说明。在Spcific runners中有红色的URL和token,这两个数据在配置runner时会用到。
1.安装runner
详细安装及Docker的安装
2.配置runner
注册runner,操作时会要求输入上文提到的URL和token,这里我们runner的执行程序用的是shell,所以在excutor选择shell。命令如下:
配置成功后,我们的项目状态如下,变为running:
ci-04.png
之后运行顺利的话,会出现绿色标志:
ci-05.png
单击Commit的ID可以查看运行详细信息,错误的信息还是成功后的信息。