本文档是用rpm包安装的,如需源码安装请参考文档:
![](/upload/ad_content/xuanchuantu-13.jpg)
成都创新互联公司专业为企业提供
福安网站建设、福安做网站、福安网站设计、福安网站制作等企业网站建设、网页设计与制作、福安企业网站模板建站服务,十余年
福安做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
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自动集成](/upload/otherpic36/42231.jpg)
二: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自动集成](/upload/otherpic36/42232.jpg)
三:使用gitlab-runner
1:在gitlab的test2i项目下创建文件.gitlab-ci.yml
![gitlab-ci自动集成](/upload/otherpic36/42233.jpg)
.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自动集成](/upload/otherpic36/42234.jpg)
注:
1:script执行命令的脚本是以gitlab-runner用户运行的,要通过sudo提权运行,不然用shell脚本自动化部署项目会报权限错误
2:执行的脚本文件要放在gitlab-runner服务器上
Commit提交到服务器后,点击pipelines会显示构建失败,失败的原因是因为test2项目没有连接上gitlab-runner
![gitlab-ci自动集成](/upload/otherpic36/42235.jpg)
2:把项目test2加入到gitla-runner里面去:激活test2项目
![gitlab-ci自动集成](/upload/otherpic36/42236.jpg)
3:修改test2项目下的文件,commit看看效果
![gitlab-ci自动集成](/upload/otherpic36/42237.jpg)
会有绿色标识显示执行成功,看看输出的结果:
![gitlab-ci自动集成](/upload/otherpic36/42238.jpg)
本教程只是简单的描述下gitlab-ci自动集成的使用,能够自定义的自动化部署你在gitlab里面的项目,完美的替换了jenkins
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网页标题:gitlab-ci自动集成-创新互联
当前链接:
http://shouzuofang.com/article/deodoc.html