gitlab-runner安装与升级
gitlab-runner介绍
GitLab Runner 是 GitLab CI/CD 的一个组件,用于运行构建、测试和部署作业。它是一个开源项目,允许您在专用、共享或云计算资源上执行作业。
Gitlab-runner安装
linux包安装gitlab-runner
gitlab Runner下载地址:https://packages.gitlab.com/runner/gitlab-runner
添加GitLab repository: For Debian/Ubuntu/Mint:
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash
For RHEL/CentOS/Fedora:
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" | sudo bash
安装gitlab runner For Debian/Ubuntu/Mint:
sudo apt-get install gitlab-runner=16.5.0
For RHEL/CentOS/Fedora:
sudo yum install gitlab-runner-16.5.0-1
上面官网给的命令实测无法安装,应该是网络问题
用国内的软件仓库安装
gitlab-runner | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
以redhat为例
vim /etc/yum.repos.d/gitlab-runner.repo
复制以下内容:
[gitlab-runner]
name=gitlab-runner
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el$releasever-$basearch/
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
yum makecache //更新缓存
yum search --showduplicates gitlab-runner //查看有哪些版本
yum install -y gitlab-runner //安装最新版
Docker安装gitlab-runner
Vi docker-compose.yml
version: '3.8'
services:
gitlab-runner:
image: 'gitlab/gitlab-runner:v17.2.1'
container_name: "gitlab-runner"
restart: always
volumes:
- '/docker/gitlab-runner:/etc/gitlab-runner'
- '/var/run/docker.sock:/var/run/docker.sock'
进入容器
docker exec -it gitlab-runner bash
查看版本
Gitlab-runner -v
注册runner
gitlab-runner register
Gitlab-runner升级
注意
gitlab-runner版本最好与gitlab版本一致
Linux安装包部署的gitlab-runner升级
Yum install gitlab-runner 后面跟版本号
gitlab-runner配置文件位置: /etc/gitlab-runner/config.toml
Docker部署的gitlab-runner升级
需要在docker-compose.yml改版本,然后执行docker-compose up –d
配置.gitlab-ci.yml
.gitlab-ci.yml文件是GitLab CI/CD流程的配置文件
详解:https://hellogitlab.com/CI/gitlab/X_gitlab_ci_.gitlab-ci.yml_detail#gitlab-ci-yml%E9%85%8D%E7%BD%AE%E5%8F%82%E6%95%B0
stages:
- build
- test
- deploy
step1:
stage: build
tags:
- test
script:
- echo "Building the project..."
step2:
stage: test
tags:
- test
script:
- echo "Running tests..."
step3:
stage: deploy
tags:
- test
script:
- echo "Deploying the project..."
stages用于定义CI/CD流程中的阶段,会按照build,test,deploy顺序执行任务
script是作业中唯一必须的关键字参数,是运行器需要执行的脚本
tags关键字用于指定作业所需的执行节点标签(Tags)。它的作用是告诉GitLab Runner只有具有指定标签的执行节点才能运行该作业。