官方文档: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
共两步:1.安装配置GitLab Runner 2.编写提交.gitlab-ci.yml文件。配置完成后每次提交或推送都会触发CI
其他系统下安装见非常详细的官方文档,以下仅演示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
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
sudo gitlab-runner register
本示例演示的基于官网GitLab的使用,若你已搭建GitLab私库填写你得地址即可
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://gitlab.com
Please enter the gitlab-ci token for this runner
xxx
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
Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
shell
.gitlab-ci.yml
文件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 "部署完成"
更多详见官方文档 https://docs.gitlab.com/ee/ci/yaml/README.html
build:
# 该阶段设置为手动触发
when: manual
stage: build
build:
# 指定tags标签为xboot的Runner执行
tags:
- xboot
stage: build