gitlab-ci自动集成
admin
2023-03-20 00:01:31
0

本文档是用rpm包安装的,如需源码安装请参考文档:

https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md

环境:

  gitlab服务器:10.0.10.50     centos7.3

   gitlab-runner服务器:10.0.10.30   centos7.3

 

 

一:gitlab的安装和使用:

1:到gitlab官网下载相对应的版本:https://about.gitlab.com/installation/
rpm -ivh   gitlab-ce-9.2.5-ce.0.el7.x86_64.rpm
 
2:修改gitlab的配置文件中的host,默认是本机的主机名
[root@gitlab-ci system]# vim /var/opt/gitlab/gitlab-rails/etc/gitlab.yml
启动方式一:
[root@gitlab-ci system]# systemctl start gitlab-runsvdir
启动方式二:
[root@gitlab-ci opt]# gitlab-ctl  start
注:防火墙和selinux注意开放


 

3:在浏览器输入地址:

http://10.0.10.50       提示修改密码,用户名是root,进入后创建项目test2


gitlab-ci自动集成

 

二:gitlab-runner的安装和使用
1:安装
For Debian/Ubuntu
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.deb.sh | sudo bash
For RHEL/CentOS
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh | sudo bash
For Debian/Ubuntu
sudo apt-get install gitlab-runner
For RHEL/CentOS
sudo yum install gitlab-runner
参考文档:https://docs.gitlab.com/runner/install/linux-repository.html#installing-the-runner
 
运行gitlab-runner,参考文档:https://docs.gitlab.com/runner/register/index.html
运行以下命令:
sudo gitlab-runner register
输入您的GitLab实例网址:
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )https://10.0.10.50
输入您获得的用于注册Runner的令牌:
Please enter the gitlab-ci token for this runner 6Rz9bnmtcC8f4jQHwo8q
输入Runner的描述,您可以稍后在GitLab的UI中进行更改:
Please enter the gitlab-ci description for this runner[hostame] my-runner
输入与Runner关联的标签,您可以稍后在GitLab的UI中进行更改:
Please enter the gitlab-ci tags for this runner (comma separated):my-tag,another-tag
选择Runner是否应该接收没有标签的作业,您可以稍后在GitLab的UI中进行更改(默认为false):
Whether to run untagged jobs [true/false]:[false]: true
选择是否将Runner锁定到当前项目,您可以稍后在GitLab的UI中进行更改。当Runner是特定的(默认为false)时有用:
Whether to lock Runner to current project [true/false]:[false]: false
输入Runner执行者:
Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:docker
2:注册成功后,启动gitlab-runner
[root@os7 ~]# gitlab-runner start


3:到gitlab服务器下看下gitlab-runner的状态

访问url:http://10.0.10.50/admin/runners

gitlab-ci自动集成 

 

三:使用gitlab-runner

1:在gitlabtest2i项目下创建文件.gitlab-ci.yml

gitlab-ci自动集成 

.gitlab-ci.yml文件的语法请参考以下文档:

http://10.0.10.50/help/ci/yaml/README.md   

gitlab-ci支持的模板示例文档。如PHP,JAVA,IOS等    

http://10.0.10.50/help/ci/examples/README.md      

 

.gitlab-ci.yml文件的内容:

gitlab-ci自动集成 

注:

    1script执行命令的脚本是以gitlab-runner用户运行的,要通过sudo提权运行,不然用shell脚本自动化部署项目会报权限错误

    2:执行的脚本文件要放在gitlab-runner服务器上

 

 

 

Commit提交到服务器后,点击pipelines会显示构建失败,失败的原因是因为test2项目没有连接上gitlab-runner

gitlab-ci自动集成 

2:把项目test2加入到gitla-runner里面去:激活test2项目

gitlab-ci自动集成 

3:修改test2项目下的文件,commit看看效果

gitlab-ci自动集成 

会有绿色标识显示执行成功,看看输出的结果:

gitlab-ci自动集成 

本教程只是简单的描述下gitlab-ci自动集成的使用,能够自定义的自动化部署你在gitlab里面的项目,完美的替换了jenkins

 


相关内容

热门资讯

最新引进“微信链接牛牛可以开挂... 最新引进“微信链接牛牛可以开挂吗?”(太坑了果然有挂)您好,微信链接牛牛这个游戏其实有挂的,确实是有...
【第一财经】“卡贝大厅怎么装挂... 【第一财经】“卡贝大厅怎么装挂?”(原来真的有挂)您好,卡贝大厅这个游戏其实有挂的,确实是有挂的,需...
超百位行业“新生力”共探AI时... 12月25日,在论坛圆桌环节,五位行业大咖围绕“智造引擎,AI如何赋能出海增长链”展开深度对话,为中...
2025年三亚市医疗器械安全突... 为提升医疗器械安全突发事件应急处置能力,健全完善应急指挥体系,切实保障人民群众生命健康安全,12月2...
玩家攻略科普“推大石28杠开挂... 网上科普关于“推大石28杠有没有挂”话题很是火热,小编也是针对推大石28杠作*弊开挂的方法以及开挂对...
【第一财经】“欢乐驿站辅助器?... 网上科普关于“欢乐驿站有没有挂”话题很是火热,小编也是针对欢乐驿站作*弊开挂的方法以及开挂对应的知识...
【第一财经】“天天乐清十三水是... 网上科普关于“天天乐清十三水有没有挂”话题很是火热,小编也是针对天天乐清十三水作*弊开挂的方法以及开...
玩家最新攻略“决战武穴麻将真的... 家人们!今天小编来为大家解答决战武穴麻将透视挂怎么安装这个问题咨询软件客服徽9752949的挂在哪里...
终于懂了“欢乐龙城9到底有挂吗... 您好:欢乐龙城9这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9752949】很多玩家在这款游...
玩家攻略科普“大唐麻将有没有挂... 您好:大唐麻将这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9784099】很多玩家在这款游戏...