Ubuntu 18.04 安装 gitlab & gitlab-runner

本文初步介绍了在 Ubuntu 18.04 上安装 gitlab-ce 以及 gitlab runner 的方法. gitlab-ce 在收到代码的提交后可以触发gitlab runner 执行 CI 命令. gitlab runner 默认使用 gitlab-runner 的账号运行 CI 命令.

gitlab

  • 运行官方提供的脚本添加安装源:

    1
    sudo curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

    安装完成后可以查看可以选择安装的版本:

    1
    apt-cache madison gitlab-ce
  • 安装 gitlab-ce

    1
    sudo apt-get install gitlab-ce=13.11.3-ce.0
  • 配置 gitlab-ce

    修改 /etc/gitlab/gitlab.rb 中的 external url, 设置为服务器的 IP 地址: external_url ‘http://192.168.0.1'. 修改完成后应用配置并启动服务

    1
    2
    gitlab-ctl reconfigure
    gitlab-ctl status

gitlab runner

安装 gitlab runner 时要尽量选择与 gitlab-ce 相同的版本.

  • 运行官方提供的脚本添加安装源:

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

    安装完成后可以查看可以选择安装的版本:

    1
    apt-cache madison gitlab-runner
  • 安装 gitlab-runner

    1
    sudo apt-get install gitlab-runner=13.11.0
  • 注册 gitlab-runner

    其中 token 在 gitlab 中的 Admin Area > Runner 中可以找到, 并在注册完毕后取消勾选 Lock to current projects 选项以解锁这个gitlab runner.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    gitlab-runner register

    [root@runner gitlab_ci]# ./gitlab-runner register
    Runtime platform arch=amd64 os=linux pid=37194 revision=a8a019e0 version=12.3.0
    Running in system-mode.

    Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
    http://10.154.172.173/
    Please enter the gitlab-ci token for this runner:
    _sAP33YvzuAxX4LnkmP5
    Please enter the gitlab-ci description for this runner:
    [runner ]: for_test
    Please enter the gitlab-ci tags for this runner (comma separated):
    for_test
    Registering runner... succeeded runner=_sAPk3Yv
    Please enter the executor: parallels, shell, virtualbox, docker+machine, custom, docker, docker-ssh, ssh, docker-ssh+machine, kubernetes:
    shell
    Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!