- 宣传官网 http://xb.exrick.cn
- 在线Demo http://xboot.exrick.cn
- 开源版Github地址 https://github.com/Exrick/x-boot
- 开发文档 https://www.kancloud.cn/exrick/xboot/1009234
- 获取完整版 http://xpay.exrick.cn/pay?xboot
官方文档:https://docs.gitlab.com/ee/ci/README.html
官方各语言项目CI示例:https://gitlab.com/help/ci/examples/README.md
学习GitLab CI文件如何编写:https://docs.gitlab.com/ee/ci/yaml/README.html
GitLab Runner安装:https://docs.gitlab.com/runner/install/index.html
GitLab CI
共两步:1.安装配置GitLab Runner 2.编写提交.gitlab-ci.yml文件。配置完成后每次提交或推送都会触发CI
GitLab Runner安装与配置
其他系统下安装见非常详细的官方文档,以下仅演示Linux环境下
- 下载二进制文件(若下载速度过慢建议本地复制链接
https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
使用下载工具如迅雷下载后上传或找其他国内镜像):
# Linux x86-64
sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
- 赋予它执行权限:
sudo chmod +x /usr/local/bin/gitlab-runner
- 创建GitLab CI用户:
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
- 安装并作为服务运行:
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
停止服务:
sudo gitlab-runner stop
- 开始GitLab Runner注册,运行以下命令:
sudo gitlab-runner register
- 输入您的GitLab实例URL:
本示例演示的基于官网GitLab的使用,若你已搭建GitLab私库填写你得地址即可
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://gitlab.com
- 输入您获得的令牌以注册Runner:
Please enter the gitlab-ci token for this runner
xxx
<img src="https://i.loli.net/2019/05/14/5cdadb9e2c9f940547.png" alt="WX20190514-230945@2x.png" title="WX20190514-230945@2x.png" width="600px" />
- 输入Runner的描述,您可以稍后在GitLab的UI中更改:
Please enter the gitlab-ci description for this runner
xboot
标签的作用可用于指定使用具体哪一个GitLab Runner,如服务器1和服务器2
Please enter the gitlab-ci tags for this runner (comma separated):
xboot
- 输入 Runner执行程序 (如果您选择Docker作为执行程序,则会要求您配置默认镜像:
Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
shell
-
安装配置完毕
编写.gitlab-ci.yml
文件
- DEMO示例
stages:
- build
- test
- deploy
# 构建阶段
build:
stage: build
# 构建脚本命令
script:
- echo "开始构建"
- echo "mvn clean..."
- echo "构建结束"
# 测试阶段
test:
stage: test
script:
- echo "运行单元测试"
- echo "java -test..."
- echo "测试结束"
# 部署阶段
deploy:
stage: deploy
script:
- echo "开始部署"
- echo "mvn install..."
- echo "部署完成"
-
提交该文件后即可在CI-流水线菜单中查看到执行的阶段进度与结果
-
可点击进入在控制台查看具体详情日志
部分常用Gitlab YAML说明
- 手动触发,关键字when定义何时开始,on_success,on_failure,always或者manual
build:
# 该阶段设置为手动触发
when: manual
stage: build
- 指定Runner,使用关键字tags指定Runner(同时Runner也要设置tags)
build:
# 指定tags标签为xboot的Runner执行
tags:
- xboot
stage: build