GitLab CI


官方文档: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环境下

  1. 下载二进制文件(若下载速度过慢建议本地复制链接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
  1. 赋予它执行权限:
sudo chmod +x /usr/local/bin/gitlab-runner
  1. 创建GitLab CI用户:
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
  1. 安装并作为服务运行:
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start

停止服务:sudo gitlab-runner stop

  1. 开始GitLab Runner注册,运行以下命令:
sudo gitlab-runner register
  1. 输入您的GitLab实例URL:

本示例演示的基于官网GitLab的使用,若你已搭建GitLab私库填写你得地址即可

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://gitlab.com
  1. 输入您获得的令牌以注册Runner:
Please enter the gitlab-ci token for this runner
xxx

image

WX20190514-230945@2x.png
  1. 输入Runner的描述,您可以稍后在GitLab的UI中更改:
Please enter the gitlab-ci description for this runner
xboot
  1. 输入 与Runner关联标签 ,您可以稍后在GitLab的UI中更改,逗号分隔:

标签的作用可用于指定使用具体哪一个GitLab Runner,如服务器1和服务器2

Please enter the gitlab-ci tags for this runner (comma separated):
xboot
  1. 输入 Runner执行程序 (如果您选择Docker作为执行程序,则会要求您配置默认镜像:
Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
shell
  • 安装配置完毕
    image
编写.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-流水线菜单中查看到执行的阶段进度与结果
    WX20190515-010603@2x.png

  • 可点击进入在控制台查看具体详情日志
    WX20190515-010817@2x.png

部分常用Gitlab YAML说明

更多详见官方文档 https://docs.gitlab.com/ee/ci/yaml/README.html

  • 手动触发,关键字when定义何时开始,on_success,on_failure,always或者manual
build:
  # 该阶段设置为手动触发  
  when: manual
  stage: build

QQ20190515-154011@2x.png

  • 指定Runner,使用关键字tags指定Runner(同时Runner也要设置tags)
build:
  # 指定tags标签为xboot的Runner执行
  tags: 
    - xboot
  stage: build
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值