gitlab-ci 初探

GitLab部署自动化集成GitLab-CI

安装&注册

  • GitLab-CI需要安装Gitlab-runner
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash ;                     
yum install gitlab-runner ;

配置Runner

默认情况,Runner是通过gitlab-runner的这个用户来执行一系列操作,其工作目录也是在gitlab-runner的用户目录下面。如果使用默认gitlab-runner用户操作一些文件时经常会遇到权限问题,就需要给gitlab-runner赋权。我们通过以下方式修改

useradd gitlab-ci -s /sbin/nologin -M ;         ##创建gitlab-ci用户
gitlab-runner uninstall ;					    ##删除默认服务
gitlab-runner install --working-directory /data/builds --user gitlab-ci;    ##重新注册服务
gitlab-runner restart;

注册Runner

先打开GitLab上需要自动部署的项目界面,找到该项目的Settings –> CI/CD –> Runners settings 在gitlab上可以看到自己的token信息,用来注册runner(也可以前往系统设置注册,再分配)

项目——设置——CI/CD——runner
在这里插入图片描述

gitlab-runner register									## 开始注册


Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):   ##输入URL
http://192.168.1.251/
Please enter the gitlab-ci token for this runner:                        ##项目对应的token
SURPSbXCMek8kkx7AWE6
Please enter the gitlab-ci description for this runner:                  ##runner说明
[localhost.localdomain]: oms_runner
Please enter the gitlab-ci tags for this runner (comma separated):       ##标签与yml中对应
web
Registering runner... succeeded                     runner=SURPSbXC
Please enter the executor: docker-ssh, parallels, virtualbox, docker+machine, docker-ssh+machine, kubernetes, custom, docker, shell, ssh:                     ##运行方式
shell

注册完成后会在网页处显示

在这里插入图片描述

  • 在对应的仓库中添加.gitlab-ci.yml文件
oms_dev:
  stage: build
  script:
    - /usr/local/sbin/sh/git_dev.sh
  environment:
    name: oms_test
    url: http://test.ashsh.com.cn
  only:
    - dev
  tags:
    - test
oms_test:
  stage: build
  script:
    - /usr/local/sbin/sh/git_test.sh
  environment:
    name: oms_test
    url: http://test.ashsh.com.cn
  only:
    - test
  tags:
    - test
oms_master:
  stage: build
  script:
    - /usr/local/sbin/sh/git_master.sh
  environment:
    name: oms_master
    url: http://master.ashsh.com.cn
  only:
    - master
  tags:
    - test

提交yml文件后,所有的push操作都会触发改文件定义的命令,脚本。

yml配置参考:https://docs.gitlab.com/ee/ci/yaml/README.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值