CentOS 以及 Windows 安装CI

ps:gitlab-runner和gitlab不需要在同一台机器上。。。

1. 安装

CentOS安装:

添加GitLab的官方存储库

curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash


安装最新版本的GitLab Runner,或特定版本

最新版本:

sudo yum install gitlab-runner

特定版本:

# for DEB based systems

apt-cache madison gitlab-runner 

sudo apt-get install gitlab-runner=10.0.0

# for RPM based systems

yum list gitlab-runner --showduplicates | sort -r

sudo yum install gitlab-runner-10.0.0-1

Windows 安装

在系统中的某个位置创建一个文件夹:

如:C:\GitLab-Runner

下载所需要的二进制文件

x86:https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-windows-386.exe

x64:https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-windows-amd64.exe

其他版本:https://docs.gitlab.com/runner/install/bleeding-edge.html#download-any-other-tagged-release

下载完后把文件重命名为 gitlab-runner.exe

2.注册runner

CentOS:

sudo gitlab-runner register

Windows:

运行CMD,进入GitLab-Runner

cd C:\GitLab-Runner

gitlab-runner.exe register

后续:

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
http://118.25.215.105/   # 填写刚才看到的URL
Please enter the gitlab-ci token for this runner
eHjxzfuVz4bx9cB8Fbim    # 填写刚才看到的Token
Please enter the gitlab-ci description for this runner:
[dev_srv]:test-runner2       # 描述一下该runner,和下面的tags相同即可 
Please enter the gitlab-ci tags for this runner (comma separated):
test-runner2                # 该runner起个名字
Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
shell                  # 填写runner执行时需要使用什么执行器,一般都填shell或者docker。
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! 

3.Windows后续安装服务,CentOS跳过

安装Runner Service服务

系统默认用户

gitlab-runner install

gitlab-runner start

用户帐户

gitlab-runner install --user ENTER-YOUR-USERNAME --password ENTER-YOUR-PASSWORD

gitlab-runner start

4.在项目根目录创建 .gitlab-ci.yml

stages:
- build

job1:
    stage: build
    script:
    - pwd
    only:
    - master
    tags:
    - test-runner2

5.查看结果

安装过程中遇到的问题:

如果出现黑色三角形,显示无法连接

可以尝试更新runner

sudo yum update

sudo yum install gitlab-runner

Windows在安装过CI后运行报错9009

首先先确认Windows上已经安装了git客户端,并且配置了环境变量,因为需要通过git来clone代码

后面错误大致意思是:没有git clone repository成功,并且没有权限访问

解决方法:

在之前二进制文件所在文件夹里运行后会产生一个.toml的文件,这个文件是Windows注册的信息,打开它

在[[runners]]节点后面添加:

shell = 'powershell'

保存之后运行成功

参考:

https://docs.gitlab.com/runner/

https://www.cnblogs.com/xishuai/p/gitlab-ci.html

猜你喜欢

转载自blog.csdn.net/qq_37143673/article/details/85095092