gitlab-runner自动化部署配置
安装docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce-18.06.0.ce -y
systemctl start dockr
systemctl enable docker
配置gitlab-runner
参考官网地址Girlab Runner https://docs.gitlab.com/runner/install/
使用命令在Docker中安装Gitlab Runner
docker run -d --name gitlab-runner --restart always -v /srv/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest
注册并设置Gitlan Runner
访问Gitlab获取http://你的gitlab地址/admin/runners
进入项目设置中》选择CI/CD
设置》Runner
找到url和令牌,记下了。后面gitlab-runner需要使用
运行Gitlab Runner注册设置
docker exec -it gitlab-runner gitlab-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://git.xd5u.cn/
Please enter the gitlab-ci token for this runner:
eF8wyzi****2RhgTHMis
Please enter the gitlab-ci description for this runner:
[6d1bc8938869]:
Please enter the gitlab-ci tags for this runner (comma separated):
demo
Whether to run untagged builds [true/false]:
[false]: true
Whether to lock the Runner to current project [true/false]:
[true]: true
Registering runner... succeeded runner=eF8wyziy
Please enter the executor: shell, ssh, docker+machine, docker, docker-ssh, parallels, virtualbox, docker-ssh+machine, kubernetes:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
以上
第一个参数输入gitlab-url,
第二个参数输入token
第三个参数输入描述
第四个参数输入标签tag
第五个参数选择执行的命令之类的,我选择了shel,可以根据自身需求选择。
注册完之后,在我的管理后台,已经有一个标签为pro的runner了,而且还是**状态,说明可以直接使用了,至此已经配置部分已经配置完毕了。
自动部署脚本.gitlab-ci.yml添加
在项目的根目录添加一个 .gitlab-ci.yml
文件
stages:
- build
- test
job 1:
stage: build
script:
- echo "222222222"
tags:
- pro
job 2:
stage: test
script:
- echo "222222222"
tags:
- pro
上面脚本说明:
stages 有两个步骤,一个是 build一个是test
job1 执行 build 步骤,这个job1可以自定义名称。但是build不可更改,
script: 后面配置执行的shell脚本
tags:指定runner的标签,我注册ruanner的时候标签填写的是pro,于是脚本中,我填写的也是pro
可以多个步骤,根据需要自定义脚本