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

gitlab ci/cd 简单流程介绍_第1张图片
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 [email protected]: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


gitlab ci/cd 简单流程介绍_第2张图片
pipelines
gitlab ci/cd 简单流程介绍_第3张图片
pipelines

2.jobs


gitlab ci/cd 简单流程介绍_第4张图片
jobs

说明

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

你可能感兴趣的:(gitlab ci/cd 简单流程介绍)