您的位置:首页 > 其它

gitlab CI

2017-06-25 11:35 267 查看
注意:gitlab 的CI 功能是版本>=8.0才有,如何安装gitlab可以自行搜索,或者点击 官方网站-安装gitlab

CI-官网

1.第一步 Add .gitlab-ci.yml to the root directory of your repository

[root@deployment ~]# mkdir test
[root@deployment ~]# cd test/
[root@deployment test]# git clone http://deployment/root/hello-world.git 正克隆到 'hello-world'...
Username for 'http://deployment': root
Password for 'http://root@deployment':
fatal: Authentication failed for 'http://deployment/root/hello-world.git/'
[root@deployment test]# git clone http://deployment/root/hello-world.git 正克隆到 'hello-world'...
Username for 'http://deployment': root
Password for 'http://root@deployment':
fatal: Authentication failed for 'http://deployment/root/hello-world.git/'
[root@deployment test]# git clone http://deployment/root/hello-world.git 正克隆到 'hello-world'...
Username for 'http://deployment': root
Password for 'http://root@deployment':
warning: 您似乎克隆了一个空版本库。
[root@deployment test]# ll
总用量 0
drwxr-xr-x. 3 root root 18 6月  25 12:18 hello-world
[root@deployment test]# cd hello-world/
[root@deployment hello-world]# ll
总用量 0
[root@deployment hello-world]# git status
# 位于分支 master
#
# 初始提交
#
无文件要提交(创建/拷贝文件并使用 "git add" 建立跟踪)
[root@deployment hello-world]#

相关新建.gitlab-ci.yml文件以及提交就不多解释了
git add .gitlab-ci.yml
git commit -m "Add .gitlab-ci.yml"
git push origin master


通过页面操作也是可以的





gitlab提供了各种语言的模版,请自行摸索

添加.gitlab-ci.yml之后查看Pipelines页面,将看到如下图的效果



2.第二部Configure a Runnerinstall gitlab runner

Shared Runners 和 specific Runners 的区别请参照官方文档

本文采用的是Shared Runners

安装Runners 链接地址

docker的安装

curl -sSL https://get.docker.com/ | sh

安装Runners

curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh | sudo bash

执行以上命令后,会出现如下提示
Generating yum cache for runner_gitlab-ci-multi-runner...
导入 GPG key 0xE15E78F4:
用户ID     : "GitLab B.V. (package repository signing key) <packages@gitlab.com>"
指纹       : 1a4c 919d b987 d435 9396 38b9 1421 9a96 e15e 78f4
来自       : https://packages.gitlab.com/runner/gitlab-ci-multi-runner/gpgkey 
The repository is setup! You can now install packages.


sudo yum install gitlab-ci-multi-runner

gitlab-ci-multi-runner-9.3.0-1.x86_64.rpm                                                                                              |  29 MB  00:10:04
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装    : gitlab-ci-multi-runner-9.3.0-1.x86_64                                                                                                     1/1
GitLab Runner: creating gitlab-runner...
验证中      : gitlab-ci-multi-runner-9.3.0-1.x86_64                                                                                                     1/1

已安装:
gitlab-ci-multi-runner.x86_64 0:9.3.0-1

完毕!


配置Runners链接



注册Runner

[root@deployment hello-world]# gitlab-
gitlab-ci-multi-runner  gitlab-ctl              gitlab-psql             gitlab-rails            gitlab-rake             gitlab-runner
[root@deployment hello-world]# gitlab-runner register
Running in system-mode.

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/): http://192.168.1.105/
Please enter the gitlab-ci token for this runner:
7vs6PBYvsyDfa4vfxzXH
Please enter the gitlab-ci description for this runner:
[deployment]: gitlab-runner test
Please enter the gitlab-ci tags for this runner (comma separated):
test-tag
Whether to run untagged builds [true/false]:
[false]: true
Whether to lock Runner to current project [true/false]:
[false]: false
Registering runner... succeeded                     runner=7vs6PBYv
Please enter the executor: parallels, shell, ssh, docker-ssh+machine, kubernetes, docker-ssh, virtualbox, docker+machine, docker:
docker
Please enter the default Docker image (e.g. ruby:2.1):
ubuntu:latest
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!




注册成功之后 就会自动执行.gitlab-ci.yml 文件定义的job了

root@deployment hello-world]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
gitlab/gitlab-runner-helper   x86_64-3df822b      406664baeda2        8 minutes ago       50.48 MB
docker.io/docker              dind                7243eea1f98a        5 days ago          99.6 MB
docker.io/docker              latest              9f8e0f96efdf        5 days ago          93.99 MB






以上的报错 不会影响功能,只是解析不了域名,因为没有注册域名:)

本人觉得关键是要学会.gitlab-ci.yml文件定义的语法.gitlab-ci.yml语法

3.官方例子视频

end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  gitlab