ubuntu安装gitlab-Runner

1、下载

curl -LJO "https://gitlab-runner-downloads.s3.amazonaws.com/latest/deb/gitlab-runner_amd64.deb"

2、安装

dpkg -i gitlab-runner_amd64.deb

3、更新

dpkg -i gitlab-runner_amd64.deb

4、注册

sudo gitlab-runner register
  1. url
  2. token
  3. 描述
  4. 标签,不设置全局可用
  5. 执行方式:shell

错误解决方法

  1. ERROR: Job failed (system failure): prepare environment: exit status 1. Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information

    原因:Ubuntu 20.04版本在执行ci时会出现此错误,解决方法是删除工作目录下的.bash_logout文件

    # 查看gitlab-runner配置
    jack@k8smaster:~$ ps aux | grep gitlab-runner
    
    root      314163  0.2  0.3 143980 30740 ?        Ssl  08:06   0:01 /usr/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --user gitlab-runner
    jack      320030  0.0  0.0   6432  2624 pts/0    S+   08:14   0:00 grep --color=auto gitlab-runner
    
    # 删除.bash_logout
    jack@k8smaster:~$ sudo rm -r /home/gitlab-runner/.bash_logout
    
  1. Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.24/auth: dial unix /var/run/docker.sock: connect: permission denied

    原因:gitlab-runner账号权限不足,不能访问/var/run/docker.sock。

    # 将gitlab-runner用户加入docker组
    [root@gitlab-runner ~]# usermod -aG docker gitlab-runner
    
    # 查看
    [root@gitlab-runner ~]# groups gitlab-runner 
    
  1. 执行kubectl命令报错:The connection to the server localhost:8080 was refused - did you specify the right host or port?

    原因:gitlab-runner账号没有kubeadm配置文件。

    mkdir -p /home/gitlab-runner/.kube
    sudo cp -i /etc/kubernetes/admin.conf /home/gitlab-runner/.kube/config
    sudo chown 755 /home/gitlab-runner/.kube/config
    
  1. 启用多分支报错:Error: Cannot perform an interactive login from a non TTY device

    原因:变量受到保护,而除master分支默认被保护之外,其他分支未设置保护,无法读取被保护的变量

    将分支添加到受保护的分支下面;
    设置->仓库->Protected branches,选择要保护的分支。
    

推荐阅读更多精彩内容