登录  | 加入社区

黑狼游客您好!登录后享受更多精彩

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

查看: 1219|回复: 0

搭建Gitlab CI连续集成情况入门教程

[复制链接]

364

主题

14

帖子

0

现金

黑狼菜鸟

Rank: 1

积分
0
发表于 2018-9-17 17:27:05 | 显示全部楼层 |阅读模式 来自 法国
简朴先容Gitlab CI的功能


  • 从GitLab 8.X 开始,GitLab CI就已经集成在GitLab中,我们只要在项目中添加一个.gitlab-ci.yml文件,然后添加一个Runner,开启Runner,即可举行连续集成。而且随着GitLab的升级,GitLab CI变得越来越强盛。
GitLab Runner


  • 在没利用过Gitlab之前,我也有一个狐疑,到底Gitlab Runner是什么东西、它的作用是什么?GitLab Runner就是来实行这些构建使命的
  • 而此时又会多了一个狐疑,Gitlab CI不是也是用来运行构建使命的吗?一样平常来说,构建使命都会占用许多的体系资源(譬如编译代码),而GitLab CI又是GitLab的一部门,假如由GitLab CI来运行构建使命的话,在实行构建使命的时间,GitLab的性能会大幅降落。GitLab CI最大的作用是管理各个项目标构建状态,因此,运行构建使命这种浪费资源的事变就交给GitLab Runner来做拉!由于GitLab Runner可以安装到差别的呆板上,以是在构建使命运行期间并不会影响到GitLab的性能。
1、起首摆设安装Gitlab

起首安装git

yum install -y git
安装Gitlab依靠

yum install -y curl openssh-server openssh-clients postfix cronie policycoreutils-python
启动ssh,postfix并设置开机启动和设置防火墙规则

sudo systemctl enable sshd
sudo systemctl start sshd
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld

下载安装Gitlab

curl -sS http://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
yum install gitlab-ce

修改Gitlab设置,将external_url变量地点改为本身域名或IP地点

vim  /etc/gitlab/gitlab.rb
## GitLab URL
##! URL on which GitLab will be reachable.
##! For more details on configuring external_url see:
##! http://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
external_url 'http://gitlab.test.com'

## Roles for multi-instance GitLab
重新启动加载设置文件

gitlab-ctl reconfigure
gitlab-ctl restart

可以netstat -ntlp检察启动的服务及端口(可以看出已经启动了nginx服务及端口为80端口,以是可以直接访问前面设置的域名或IP地点)

Sk45C0ECBK449zQc.jpg
在欣赏器上访问地点(管理员账号暗码在UI界面上举行设置)

2、接下来安装与设置Gitlab Runner

点开Runners可以看到一个设置的manually![] Lr9l9vI9iGHYLlYj.jpg
点击install GitLab Runner安装Gitlab Runner
# For Debian/Ubuntu
$ curl -L http://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.deb.sh | sudo bash
$ sudo apt-get install gitlab-ci-multi-runner
# For CentOS
$ curl -L http://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh | sudo bash
$ sudo yum install gitlab-ci-multi-runner

注册Runner(这里可以选择注册一个指定的Runner大概注册一个共享的Runner)

指定的Runner可以明白为只能对某个份代码有用的一个Runner,共享Runner可以明白为全部的代码都可以应用得到同一个Runner,但是注册共享Runner只有admin权限又才可。

  • 注册一个共享的Runner(注册指定Runner也是一样的操纵)</br>
    起首admin的账号下看到Runner的设置manually的URL与token信息
    XvFEFsVaqoAoot2Q.jpg
sudo gitlab-ci-multi-runner register
cRnRv1loOi5Z1vV0.jpg

  • 输入Gitlab CI地点
  • 输入项目Gitlab CI token
  • 输入Gitlab Runner形貌
  • 输入Gitlab Runner标签
  • 输入Gitlab Runner实行的语言
可以检察在Gitlab 共享Runner上多了一条Runner记载
P0000sicFRFm9i44.jpg
也可以利用list检察Runner的状态:
gitlab-runner  list
Listing configured runners                          ConfigFile=/etc/gitlab-runner/config.toml
cml_test*.*.172.123                          Executor=shell Token=ece68d167647507d1aa61d80ca0f05 URL=http://gitlab.test.com/


  • 接下来编写.gitlab-ci.yml文件,推送到长途代码堆栈。
    这里演示一个简朴的git pull操纵

cat .gitlab-ci.yml
# 界说 stages
stages:
  - test

# 测试
test:
  stage: test
  script:
    # Deploy test
    - ansible cml_test*.*.172.123 -a "cd /home/www/test;git pull"

(这里我利用了ansible去管理,更新代码操纵)
末了推送到长途代码堆栈上去。

git add .
git commit -m "fix .gitlab-ci.yml"
git push


  • 在相应的代码库下开启的这个共享Runner。
    PPfkDVnuPzyu8NzY.jpg
提交接码触发CI

daMd5WHHKOXTHAUW.jpg
来自:51cto.com/legehappy




上一篇:python3测试工具开辟快速入门教程6模块
下一篇:专员的eos教程第一篇——底子情况预备
您需要登录后才可以回帖 登录 | 加入社区

本版积分规则

 

QQ|申请友链|小黑屋|手机版|Hlshell Inc. ( 豫ICP备16002110号-5 )

GMT+8, 2024-6-25 14:51 , Processed in 0.063414 second(s), 47 queries .

HLShell有权修改版权声明内容,如有任何爭議,HLShell將保留最終決定權!

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表