1gittlab,配置本地Git.

2 添加项目到CI(Continues Integration)中

gitlab ci 配置_docker

ci-01.png

3 单击项目,进入CI页面中

第一次没有配置的情况下:

gitlab ci 配置_git_02

ci-02.png

4 添加".gitlab-ci.yml"文件

".gitlab-ci.yml"文件放在仓库的根目录下,用来设置gitlab项目的runner,每次在push的时候自动触发项目的build。
首先在项目的根目录下(git clone ...)创建'.gitlab-ci.yml'文件,针对新建的示例项目创建简单的内容:

 

stages:
- build
- test
- deploy
b1:
stage: build
script:
- uname -a
- g++ hello.cpp
- bash scripts
tags:
- shell
t1:
stage: test
script:
- ./a.out
tags:
- shell

文件包含多个stage,如build、test、deploy,每个相同的stage运行都是并行的,而后面的stage必须在前面的stage运行结束才能开始。script表示运行命令,示例中以shell命令为例。tags表示runner的标签,用哪个runner来build项目,关于runner的配置在下一章中。
另外,在build完项目后,可以添加一个脚本用来进行测试程序,如'-bash scripts'。
添加文件"hello.cpp"和".gitlab-ci.yml",然后push到gitlab。

 

$git add hello.cpp .gitlab-ci.yml
$git commit -a
$git push origin master

成功之后,commit的状态为"pending",意思是正在等待中,因为还没有runner来执行。

gitlab ci 配置_bash_03

转存失败重新上传取消

image

关于文件格式内容的详细说明​​.gitlab-ci.yml​

5 配置Runner

单击网页左侧Runners。

gitlab ci 配置_bash_04

ci-03.png

有"Specific runners"和"Shared runners"两种,我们只介绍"Specific runners"的配置,关于runner的详细说明。在Spcific runners中有红色的URL和token,这两个数据在配置runner时会用到。

1.安装runner

 

$sudo apt-get update
$sudo apt-get install gitlab-ci-multi-runner

详细安装及​​Docker​​的安装

2.配置runner

注册runner,操作时会要求输入上文提到的URL和token,这里我们runner的执行程序用的是shell,所以在excutor选择shell。命令如下:

 

$sudo gitlab-ci-multi-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci )
http://gitlab.###.io/ci
Please enter the gitlab-ci token for this runner
########################
Please enter the gitlab-ci description for this runner
my-runner
INFO[0034] fcf5c619 Registering runner... succeeded
Please enter the executor: shell, docker, docker-ssh, ssh?
shell
INFO[0037] Runner registered successfully. Feel free to start it, but if it's
running already the config should be automatically reloaded!

配置成功后,我们的项目状态如下,变为running:

gitlab ci 配置_git_05

ci-04.png

之后运行顺利的话,会出现绿色标志:

gitlab ci 配置_git_06

ci-05.png

单击Commit的ID可以查看运行详细信息,错误的信息还是成功后的信息。