- 安装gitlab-runner
-
docker run -d --name gitlab-runner --restart always -v /srv/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest
-
- 注册gitlab-runner
-
docker run --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register
- Enter your GitLab instance URL (also known as the
gitlab-ci coordinator URL
) - Enter the token you obtained to register the runner
- Enter a description for the runner. You can change this value later in the GitLab user interface.
- Enter the tags associated with the runner, separated by commas. You can change this value later in the GitLab user interface.
- Provide the runner executor. For most use cases, enter
docker
- If you entered
docker
as your executor, you’ll be asked for the default image to be used for projects that do not define one in.gitlab-ci.yml
-
- 重启 & 停止 & 再启动
-
# 重启 docker restart gitlab-runner # 停止和删除 docker stop gitlab-runner && docker rm gitlab-runner #再启动 docker run -d --name gitlab-runner --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner:latest
- 在gitlab面板上刷新下看到下图则说明配置成功
-
- 获取日志
-
docker logs gitlab-runner
-
- 修改配置文件:
- sudo vi /srv/gitlab-runner/config/config.toml
- 增加pull_policy = "if-not-present"
- 常用配置选项
- USAGE:
- gitlab-runner run [command options] [arguments...]
- OPTIONS:
- -c value,
- --config value 配置文件路径,.toml结尾
- --listen-address value 端口
- -n value,
- --service value 服务名称,默认是gitlab-runner -d value,
- --working-directory value 工作目录,也就是从gitlab clone项目的目录,默认是当前目录
- -u value,
- --user value 执行shell脚本所用的用户
- --syslog 日志
- 举例:假设我们有自己的配置文件,已经专门的gitlab-runner账号,则启动指令可以改为
- sudo gitlab-runner run -c config.toml -u runner&
- USAGE:
- 在项目根目录中增加.gitlab-ci.yml文件
-
stages: - pylint - test pylint-job: tags: - zone_v1 image: eureca2020/ubuntu18.04:v1.1 stage: pylint script: - find . \( -path ./qt -o -path ./3rdparty \) -prune -o -type f -name "*.py" | xargs pylint test-job: tags: - zone_v1 stage: test image: eureca2020/ubuntu18.04:v1.1 script: - sh test/run_test.sh
-
-
代码仓存在子仓(submodules时)
- 子仓需要配置 Deploy tokens,否则会出现submodule checkout权限问题
- 进入子项目,左侧菜单栏,打开settings/repository/deploy_tokens:
- 创建完成后,复制 username 和 deploy_token 来配置
.gitmodules
文件 - [submodule "android-sub"]
path = android-sub
url = https://<username>:<deploy_token>@gitserver.com/android/android-sub.git
- 详细问题参考:Gitlab CI 拉取 submodules_麦田里的守望者-Jiang的博客-CSDN博客_git submodule 拉取
- 子仓需要配置 Deploy tokens,否则会出现submodule checkout权限问题
- 参考:
gitlab ci部署指导
于 2021-05-31 09:47:13 首次发布