本文介绍: CICD注册和使用gitlab-runner常见问题

1、现象
fatal: unable to access ‘https://github.com/homebrew/brew/’:

2、解决

git config –global –unset http.proxy

git config –global –unset https.proxy

查看gitlab-runner是否成功:

user@users-MacBook-Pro ~ % gitlab-runner -h  

查看gitlab-runner状态:

user@users-MacBook-Pro ~ % ps -ef | grep gitlab-runner

  501  3658  3081   0  4:36PM ttys004    0:00.00 grep gitlab-runner

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7/gitlab-runner-15.8.1-1.x86_64.rpm

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7/gitlab-runner-15.0.0-1.x86_64.rpm

yum -y install gitlab-runner-15.0.0-1.x86_64.rpm

#查看运行状态

systemctl status gitlab-runner

                        

Gitlab runner安装和使用-CSDN博客

安装runner
  sudo curl –output /usr/local/bin/gitlab-runner “https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-arm64”
创建runner
这个步骤需要在gitlab中进行,有三种的runner可以创建,分别是共享、组群和项目。

创建好后复制出gitlab地址和token,接下来注册时会用到。

注册runner
注册是最关键的步骤。

gitlab-runner register
然后按顺序输入内容完成创建过程:

首先输入URL,就是创建runner时复制的那个URL;
接下来输入token,就是创建runner时复制的那个token;
然后输入description,这个description可以理解为runner名,在list里会看到;
接下里就是输入最最重要的tags,这个tags在配置.gitlab-ci.yml时需要指定,不然会导致runner无法将修改提交给CI流水线;
然后让输入一个note,直接按enter跳过即可;
最后让选择executor,由于是在mac中,输入shell即可。
不出意外就会在本机成功创建出一个runner。

运行runner
gitlab-runner restart
gitlab-runner run
如果restart失败了不用管,继续run即可

启动gitlab-runner和关闭gitlab-runner ,查看gitlab-runner不同的状态

三、gitlab-runner设置用户为root
第二步安装gitlab-runner是会默认安装一个gitlab-runner用户,CI运行期间,会出现一些权限不足的问题,所以将gitlab-runner的默认用户设为root

卸载掉gitlab-runner默认用户
sudo gitlab-runner uninstall

首先通过 sudo su -把账户切换到root账户,这样才能执行下面的命令

重新安装gitlab-runner并将用户设置为root
gitlab-runner install –working-directory /home/gitlab-runner –user root

重启gitlab-runner
sudo service gitlab-runner restart
第3步执行完后,gitlab-runner已经开始运行,不需要手动运行。
 

ubuntu搭建gitlab-runnner:

Ubuntu搭建gitlab-Ci教程_gitlab runner ubuntu-CSDN博客

如果pipline出现pengding的情况

并且有下面的报错信息

This job is stuck because of one of the following problems. There are no active runners online, no runners for the protected branch, or no runners that match all of the job’s tags: build

Go to project CI settings

解决方案:

点击runner的编辑按钮,勾选下面两个选项并且保存

需要把gitlab-ci.yml中的tags都删除,这样才能正常执行

Runners can be configured with tags of your choice when you first set them up. The purpose of tags: in .gitlab-ci.yml is to say, “only use runners with these tags”. For example, if you need a job to run on a specific server, or have CUDA access, or some other special environmental thing that generic runners don’t have, use tags. If that’s not your intention then remove tags:.

Gitlab job is stuck, no active runners, why? – Stack Overflow

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注