CI/CD: GitLab Runner安装注册配置管理

开源
GitLab Runner是用Go编写的,可以作为一个二进制文件运行,不需要特定于语言的要求。它旨在在GNU / Linux,macOS和Windows操作系统上运行。只要您可以在其他操作系统上编译Go二进制文件,其他操作系统就可能会运行。

GitLab Runner是一个开源项目,用于运行您的作业并将结果发送回GitLab。它与GitLab CI结合使用,GitLab CI是GitLab随附的用于协调作业的开源持续集成服务。

安装要求

GitLab Runner是用Go编写的,可以作为一个二进制文件运行,不需要特定于语言的要求。它旨在在GNU / Linux,macOS和Windows操作系统上运行。只要您可以在其他操作系统上编译Go二进制文件,其他操作系统就可能会运行。

如果要使用Docker,请安装最新版本。GitLab Runner需要最少的Docker v1.13.0。

GitLab Runner版本应与GitLab版本同步。

可以在GNU / Linux,macOS,FreeBSD和Windows上安装和使用GitLab Runner 。您可以使用Docker安装它,手动下载二进制文件,也可以使用GitLab提供的rpm / deb软件包的存储库。

基于centos安装

curl -LJO https://gitlab-runner-downloads.s3.amazonaws.com/latest/rpm/gitlab-runner_<arch>.rpm
rpm -i gitlab-runner_<arch>.rpm
rpm -Uvh gitlab-runner_<arch>.rpm

基于macos系统安装

sudo curl --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/v12.6/binaries/gitlab-runner-darwin-amd64
sudo chmod +x /usr/local/bin/gitlab-runner
gitlab-runner install
gitlab-runner start

基于Docker运行

mkdir ~/data/gitlab-runner/config
docker run --rm -t -id -v ~/data/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner:v12.9.0

GitLab Runner注册

  • 类型
  • shared :运行整个平台项目的作业(gitlab)
  • group:运行特定group下的所有项目的作业(group)
  • specific: 运行指定的项目作业(project)
  • 状态
  • locked:锁定无法运行项目作业
  • paused:暂停不会运行作业

获取shared类型runnertoken

图片

获取group类型的runnertoken

进入group -> Settings -> CI/CD -> Runners -> Group Runners

图片

获取specific类型的runnertoken

进入具体的项目 -> Settings -> CI/CD -> Runners -> Specific Runners。

图片

启动容器交互式注册

docker run --rm -t -i -v ~/data/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner:v12.6.0 register

Runtime platform                                    arch=amd64 os=linux pid=6 revisinotallow=ac8e767a versinotallow=12.6.0
Running in system-mode.
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://192.168.1.105
Please enter the gitlab-ci token for this runner:
4tutaeWWL3srNEcmHs1s
Please enter the gitlab-ci description for this runner:
[00e4f023b5ae]: devops-service-runner
Please enter the gitlab-ci tags for this runner (comma separated):
build
Registering runner... succeeded                     runner=4tutaeWW
Please enter the executor: parallels, virtualbox, docker-ssh+machine, kubernetes, docker+machine, custom, docker, docker-ssh, shell, ssh:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

非交互式注册

docker run -itd --rm -v ~/data/gitlab-runner/config:/etc/gitlab-runner  gitlab/gitlab-runner:v12.6.0 register \
  --non-interactive \
  --executor "shell" \
  --url "http://192.168.1.200:30088/" \
  --registration-token "JRzzw2j1Ji6aBjwvkxAv" \
  --description "devops-runner" \
  --tag-list "build,deploy" \
  --run-untagged="true" \
  --locked="false" \
  --access-level="not_protected"

效果:

图片

常用命令

启动命令:

gitlab-runner --debug <command>   #调试模式排查错误特别有用。
gitlab-runner <command> --help    #获取帮助信息
gitlab-runner run       #普通用户模式  配置文件位置 ~/.gitlab-runner/config.toml
sudo gitlab-runner run  # 超级用户模式  配置文件位置/etc/gitlab-runner/config.toml

注册命令:

gitlab-runner register  #默认交互模式下使用,非交互模式添加 --non-interactive
gitlab-runner list      #此命令列出了保存在配置文件中的所有运行程序
gitlab-runner verify    #此命令检查注册的runner是否可以连接,但不验证GitLab服务是否正在使用runner。--delete 删除
gitlab-runner unregister   #该命令使用GitLab取消已注册的runner。
#使用令牌注销
gitlab-runner unregister --url http://gitlab.example.com/ --token t0k3n
#使用名称注销(同名删除第一个)
gitlab-runner unregister --name test-runner
#注销所有
gitlab-runner unregister --all-runners

服务管理:

gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
# --user指定将用于执行构建的用户
#`--working-directory  指定将使用**Shell** executor 运行构建时所有数据将存储在其中的根目录
gitlab-runner uninstall #该命令停止运行并从服务中卸载GitLab Runner。
gitlab-runner start     #该命令启动GitLab Runner服务。
gitlab-runner stop      #该命令停止GitLab Runner服务。
gitlab-runner restart   #该命令将停止,然后启动GitLab Runner服务。
gitlab-runner status #此命令显示GitLab Runner服务的状态。当服务正在运行时,退出代码为零;而当服务未运行时,退出代码为非零。

运行Pipeline

stages:
  - build
  - deploy
build:
  stage: build
  tags:
    - build
  only:
    - master
  script:
    - echo "mvn clean "
    - echo "mvn install"
deploy:
  stage: deploy
  tags:
    - deploy
  only:
    - master
  script:
    - echo "hello deploy"

图片

GitLabCI 有助于DevOps人员,例如敏捷开发中,开发与运维是同一个人,最便捷的开发方式。JenkinsCI适合在多角色团队中,职责分明、配置与代码分离、插件丰富。

责任编辑:姜华 来源: DevOps云学堂
相关推荐

2020-10-21 14:10:28

工具测试开发

2023-04-18 08:17:11

GitLab持续集成

2020-12-31 11:28:09

GitLabCICD

2020-11-06 16:50:43

工具GitLab CICD

2023-03-13 14:46:32

CI/CD工具软件开发

2020-10-12 07:00:00

JenkinsDevOps测试工具

2021-02-22 09:43:35

GitLabCICD

2022-02-22 09:00:00

软件开发CI/CD 管道工具

2021-04-18 07:33:20

项目Springboot Nacos

2023-05-04 16:03:50

KubernetesCI/CD集成

2021-07-02 16:30:01

CICDDevOps

2020-12-15 16:13:21

DevSecOpsCICD

2015-08-12 13:44:29

UbuntuChef

2018-09-07 11:12:19

CICD工具

2023-01-30 15:55:08

2021-05-13 18:23:53

Tekton云原生Kubernetes

2023-04-10 08:11:27

Jenkins数据库

2012-10-29 16:45:07

CentOS 6.2Puppet

2022-03-26 16:53:17

阻抗开发环境部署
点赞
收藏

51CTO技术栈公众号