gitlab ci php 构建,GitLab CI的入门搭建

搭建一个GitLab CI环境分两步

在服务器配置GitLab Runner

GitLab Runner是一个用来执行持续集成脚本的网络服务,它的工作模式是

轮询GitLab仓库

一旦发现GitLab仓库中的代码分支有变化,就在服务器的工作空间内pull(拉取)最新代码

并执行项目目录下.gitlab-ci.yml中的持续集成脚本

把服务器终端的命令行日志返回给GitLab CI

下面我们在Ubuntu中配置GitLab Runner项目

安装GitLab Runner

Ubuntu系统安装什么都很简单,GitLab Runner也不例外,就下面两行代码

# 命令增加GitLab官方仓库

$ curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash

# 安装最新版本的GitLab Runner

$ sudo apt-get install gitlab-runner

注册GitLab Runner

还需要配置一下GitLab仓库的相关信息,这样GitLab Runner才能轮询GitLab仓库与GitLab CI持续集成

# 注册GitLab Runner对应的GitLab信息

$ sudo gitlab-runner register

上面的命令会要我们输入5个信息,分别是

$ Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com)

$ [GitLab URL,在GitLab仓库的`Settings -> CI/CD -> Runners`下查看]

$ Please enter the gitlab-ci token for this runner

$ [注册token,在GitLab仓库的`Settings -> CI/CD -> Runners`下查看]

$ Please enter the gitlab-ci description for this runner

$ [这个Runner的名称]

$ Please enter the gitlab-ci tags for this runner (comma separated):

$ [这个Runner的tag]

$ Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:

$ [这个Runner的执行器类型,这里用最简单的shell就好了]

注册如果顺利的话,后面的两步就非常简单了

通过.gitlab-ci.yml编写脚本

在GitLab仓库的目录下新建.gitlab-ci.yml脚本文件,正常情况下GitLab的项目主页顶部会提供快捷方式,可以一键创建.gitlab-ci.yml脚本文件

编辑.gitlab-ci.yml脚本文件,这里为了演示,就使用最简单的方式写了一个输出“GitLab仓库代码在服务器的工作空间目录”的shell脚本

stages:

- test

test-job:

stage: test

script:

- echo `pwd`

tags:

- [上一步配置的Runner的tag名称]

当你编辑完.gitlab-ci.yml脚本文件,点击保存后,在GitLab仓库的Settings -> CI/CD -> Pipelines下,就会发现你刚才保存的代码更改,成功触发了GitLab Runner服务,在服务器上执行了持续集成脚本,并可以直接看到服务器终端的执行输出及结果

ce7da5967029

服务器终端的执行输出及结果

到这里就已经完成了GitLab CI的搭建

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值