GitLab
简介
GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的Web服务
使用
- 官方地址 https://gitlab.com/
- 在官方地址中注册对应的账号,配置好SSH
- 创建一个自己的仓库,便可以将自己的代码使用git来托管了
GitLab-Runner
下载安装
- linux下载gitlab-runner(需在部署项目的服务器中下载安装)
# 添加yum源
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
# 安装gitlab-runner
yum -y install gitlab-runner
# 启动 重起 停止gitlab-runner
sudo gitlab-runner start
sudo gitlab-runner restart
sudo gitlab-runner stop
# 查看gitlab-runner运行状态
sudo gitlab-runner status
runner配置
- 打开GitLab选择一个项目组配置CICD或者只针对某一个项目进行配置。推荐使用项目组的方式,里面的项目都可以共用一个runner
找到项目群组中的cicd

选择runner
找到对应的token去注册一个runner

- 注册GitLab-runner

# 注册命令
sudo gitlab-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/)::
# 输入上面步骤找到的URL,示例:https://gitlab.xxx.com/
Please enter the gitlab-ci token for this runner:
# 输入上面步骤找到的token
Please enter the gitlab-ci description for this runner:
# 为该gitlab runner自定义一个名称,示例:love
Please enter the gitlab-ci tags for this runner (comma separated):
# 为该gitlab runner定义一组tag,以逗号隔开,表示只有匹配到这些tag,才会用该runner执行job。示例:love
Please enter the executor: docker, docker-ssh, virtualbox, docker-ssh+machine, custom, shell, ssh, docker+machine, kubernetes, parallels:
# 为该runner指定一个executor,由于这里用shell作为示例,输入:shell
#注册成功
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
# 重启gitlab-runner
sudo gitlab-runner restart
- 完成注册 注册成功后gitlab将会出现配置好了的一个runner

配置CICD文件
- 在项目的根目录创建好.gitlab-ci.yml
- 文件内容配置 (此处使用的是简单的shell命令演示,后端相关操作类型,需打包需装好maven、java等环境)
stages:
- build
cache:
key: ${CI_BUILD_REF_NAME}
paths:
- LoverTree
pro_build:
stage: build
tags:
- love
script:
- echo "Building the LoveTree"
- pwd
- rm -rf /usr/local/love/LoveTree/*
- cp -r ./* /usr/local/love/LoveTree/
#仅仅在master分支进行push的时候执行
only:
- master
- 配置好文件,进行提交 master分支在发生push改变的时候便会触发流水线,然后执行.gitlab-ci.yml文件的内容
控制台能够看到对应的命令执行 