官方快速入门文档.gitlab-ci.yml
文件官方示例
.gitlab-ci.yml完整说明
语法验证,可以在项目对应的目录/gitlab-org/project-123/-/ci/lint
进行验证
查看搭建的gitlab系统版本/api/v4/version
,返回类似{"version":"11.11.3","revision":"e3eeb779d72"}
的内容。
配置完成后,需要对应的Gitlab Runner
配合执行.gitlab-ci.yml
文件中对应的任务。runner 官方文档。
安装Gitlab CE
安装一个CE版本,自己实践一下——
#依赖
sudo apt-get install -y curl openssh-server ca-certificates
#邮件
sudo apt-get install -y postfix
#添加源
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
#安装
sudo EXTERNAL_URL="http://your.domain:port" apt-get install gitlab-ce
Reading state information... Done
The following packages were automatically installed and are no longer required:
libopts25 sntp
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
gitlab-ce
0 upgraded, 1 newly installed, 0 to remove and 50 not upgraded.
Need to get 742 MB of archives.
After this operation, 1,927 MB of additional disk space will be used.
按照固定带宽在下载,看起来要慢慢等了。
502 Whoops, GitLab is taking too much time to respond
看起来我的小破机器跑不起来gitlab的。GitLab requires at least 2GB RAM + 2GB swap memory
手动安装,下载deb包之后,执行sudo EXTERNAL_URL="http://your.domain:port" dpkg -i gitlab-ce_12.6.2-ce.0_amd64.deb
即可。
#Turn off all swap processes
sudo swapoff -a
#Resize the swap
sudo dd if=/dev/zero of=/swapfile bs=1G count=8
#if = input file
#of = output file
#bs = block size
#count = multiplier of blocks
#Make the file usable as swap
sudo mkswap /swapfile
#Activate the swap file
sudo swapon /swapfile
#Check the amount of swap available
grep SwapTotal /proc/meminfo
手动增大SWAP区域之后,至少启动起来了
# Start all GitLab components
sudo gitlab-ctl start
# Stop all GitLab components
sudo gitlab-ctl stop
# Restart all GitLab components
sudo gitlab-ctl restart
# check log
sudo gitlab-ctl tail
安装gitlab runner
官方安装文档,在已经启动的gitlab实例目录/admin/runners
下可以看到安装步骤,需要管理员权限
Set up a shared Runner manually
- Install GitLab Runner
- Specify the following URL during the Runner setup:
http://xxx.com:port/
- Use the following registration token during setup:
token-value
- Start the Runner!
GitLab Runner should be the same version as GitLab. Older runners may still work with newer GitLab versions, and vice versa. However, features may be not available or work properly if a version difference exists.
Go语言编写,二进制发布,多平台支持。
历史版本下载页面,根据 官方仓库的tag列表的不同分支,选择对应的版本——
例如,v12.6版本,分支对应为v12.6.0
,则二进制版本下载地址为https://s3.amazonaws.com/gitlab-runner-downloads/**v12.6.0**/binaries/gitlab-runner-linux-386
- 添加可执行权限:
sudo chmod +x gitlab-runner
- 创建执行用户:
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
- 安装为服务:
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
- 注册runner,即将runner与gitlab绑定。Register a runner
建议是Gitlab和Gitlab Runner分离,但不考虑安全、性能的情况下,同时在一台机器上跑没有问题。参考 CI runner on same server of GitLab?,或者 Setting up GitLab CI on server with GitLab already installed
注册runner
#拉取gitlab-runner镜像
docker pull hub.xxx-cloud.com/library/gitlab-runner
# 创建后台运行的容器
docker run -it -d -v /var/run/docker.sock:/var/run/docker.sock image_id_hash
# 进入容器。
docker exec -it container_id_hash bash
# 注册runner到gitlab-ce里,使用交互式注册
gitlab-runner register
######交互过程
gitlab-runner register
Runtime platform arch=amd64 os=linux pid=45 revision=4745a6f3 version=11.8.0
Running in system-mode.
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://git.xxx-corp.com/
Please enter the gitlab-ci token for this runner:
91WAmfZyLYYRkvD8vR7B
Please enter the gitlab-ci description for this runner:
[02f73eb2bdc7]: local-runner-on-windows-pc-for-test
Please enter the gitlab-ci tags for this runner (comma separated):
med-geb,med-test
Registering runner... succeeded runner=91WAmfZy
Please enter the executor: docker+machine, kubernetes, docker, parallels, shell, ssh, virtualbox, docker-ssh, docker-ssh+machine:
docker
Please enter the default Docker image (e.g. ruby:2.1):
hub.xxx-cloud.com/medusa/med-test:latest
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
#######交互过程结束
# 查看 /etc/gitlab-runner/config.toml 文件内容,可以看到详细的配置信息
#启动runner
gitlab-runner start
# 查看帮助
gitlab-runner --help
# 查看注册帮助
gitlab-runner register --help