devops之路gitlab runner

GitLab 8.0 开始,GitLab CI 就已经集成在 GitLab 中,我们只要在项目中添加一个 .gitlab-ci.yml 文件,然后添加一个 Runner,即可进行持续集成

gitlab runner承担gitlab ci的构建任务。

gitlab runner安装

# For Debian/Ubuntu
$ curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.deb.sh | sudo bash
$ sudo apt-get install gitlab-ci-multi-runner

注册 Runner

runner安装成功后,怎么将runner和gitlab ci工具关联起来

sudo gitlab-ci-multi-runner register
输入 CI URL
输入 Token
输入 Runner 的名字
选择 Runner 的类型,选shell

查看runner的状态

sudo gitlab-ci-multi-runner list
$ sudo gitlab-runner list
Listing configured runners          ConfigFile=/etc/gitlab-runner/config.toml
my-runner                           Executor=shell Token=cd1cd7cf243afb47094677855aacd3 URL=http://mygitlab.com/ci

runner执行任务

runner和gitlab已经建立起了关联关系,那么怎么定义runner要执行的任务呢
在gitlab代码版本库中添加.gitlab-ci.yml脚本配置文件
例如:

# 定义 stages
stages:
  - build
  - test
# 定义 job
job1:
  stage: test
  script:
    - echo "I am job1"
    - echo "I am in test stage"
# 定义 job
job2:
  stage: build
  script:
    - echo "I am job2"
    - echo "I am in build stage"

以上配置就是runner要执行的命令

相关推荐