gitlab ci cd php,gitlab ci/cd 简单流程介绍

gitlab-runner

一、安装gitlab-runner

安装环境:Ubuntu18.04

1.安装

sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64

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

sudo apt-get install gitlab-runner

2.注册

sudo gitlab-runner register

需要输入url和token等信息,可以管理员登录giblab-设置-runners 查看

3.启动|停止

sudo gitlab-runner start|stop

43a2b50a5b3d

image.png

二、编写ci、cd流程文件

仓库根目录建立文件

.gitlab-ci.yml

stages:

- clear_dir

- git_clone

- build

- deploy

clear_dir:

stage: clear_dir

script:

- cd /home/gitlab-runner/

- rm -rf ./h5

only:

- master

tags:

- shell

git_clone:

stage: git_clone

script:

- cd /home/gitlab-runner/

- git clone git@192.168.1.97:xiaojian/h5.git

only:

- master

tags:

- shell

build:

stage: build

script:

- cd /home/gitlab-runner/h5

- cnpm install

only:

- master

tags:

- shell

deploy:

stage: deploy

script:

- echo "发布中...."

only:

- master

tags:

- shell

三、启动

代码分支有新提交,自动执行部署任务

如图

1.pipelines

43a2b50a5b3d

pipelines

43a2b50a5b3d

pipelines

2.jobs

43a2b50a5b3d

jobs

说明

1.gitlab-runner 用户的sshkey导入到gitlab

2.用户gitlab-runner要目录读写权限(因为任务是用gitlab-runner用户运行的,执行如果报权限相关的错误,请检查用户权限)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值