【问题标题】:Using multiple runners in one gitlab-ci在一个 gitlab-ci 中使用多个跑步者
【发布时间】:2018-11-08 18:55:25
【问题描述】:

我想用 2 个作业运行 CI 管道:

  1. 作业将使用 docker-runner 启动 docker 映像并在 docker 内运行测试
  2. 将在 ssh runner 下运行并在远程服务器上拉取代码。

有可能吗?

【问题讨论】:

    标签: gitlab-ci gitlab-ci-runner


    【解决方案1】:

    是的,这是可能的。您需要:

    1. 向所需的 executor 注册两个 GitLab Runners(docker 和 shell),每个都有不同的标签(或者,至少其中一个带有构建标签)。
    2. 在您的.gitlab-ci.yml 中为给定的job 声明一个特定的标签。

    Shell runner 注册:

    [root@jsc00mca ~]# gitlab-runner register
    Running in system-mode.                            
    
    Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
    https://example.com/
    Please enter the gitlab-ci token for this runner:
    1a2b3c
    Please enter the gitlab-ci description for this runner:
    [jsc00mca.example.com]: my-shell-runner
    Please enter the gitlab-ci tags for this runner (comma separated):
    shell
    Whether to run untagged builds [true/false]:
    [false]: 
    Whether to lock the Runner to current project [true/false]:
    [true]:
    Registering runner... succeeded                     runner=ajgHxcNz
    Please enter the executor: virtualbox, docker+machine, kubernetes, docker, shell, ssh, docker-ssh+machine, docker-ssh, parallels:
    shell
    Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
    

    Docker 跑步者注册:

    [root@jsc00mca ~]# gitlab-runner register
    Running in system-mode.                            
    
    Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
    https://example.com/
    Please enter the gitlab-ci token for this runner:
    1a2b3c
    Please enter the gitlab-ci description for this runner:
    [jsc00mca.example.com]: my-docker-runner
    Please enter the gitlab-ci tags for this runner (comma separated):
    docker
    Whether to run untagged builds [true/false]:
    [false]: 
    Whether to lock the Runner to current project [true/false]:
    [true]:
    Registering runner... succeeded                     runner=ajgHxcNz
    Please enter the executor: virtualbox, docker+machine, kubernetes, docker, shell, ssh, docker-ssh+machine, docker-ssh, parallels:
    docker
    Please enter the default Docker image (e.g. ruby:2.1):
    alpine:latest
    Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
    

    .gitlab-ci.yml

    buildWithShell:
      stage: build
      tags:
      - shell
      script:
      - echo 'Building with the shell executor...'
    
    buildWithDocker:
      image: alpine:latest
      stage: build
      tags:
      - docker
      script:
      - echo 'Building with the docker executor...'
    

    【讨论】:

    • 这两个跑步者是否共享同一个config.toml 文件?
    • 是的,相同的配置文件。
    【解决方案2】:

    是的,您可以从单个 gitlab-ci 管道触发不同/混合的运行器。

    首先你应该在目标主机上注册一个shell runner并给它一个标签(截断):

    $ gitlab-runner register
    ...
    
    Please enter the gitlab-ci tags for this runner (comma separated):
    my_shell_runner
    ...
    Please enter the executor: virtualbox, docker+machine, docker-ssh+machine, docker, docker-ssh, parallels, shell, ssh:
    shell
    

    在你的 gitlab-ci.yaml 中,这样的东西应该可以工作。 “测试”作业基于图像 NAME_OF_IMAGE 在 docker 容器中运行您的测试命令。

    如果成功,“部署”作业会根据标签“my_shell_runner”选择您的 shell 运行器,并将执行运行器主机上脚本标签内的所有命令(截断):

     test:
       stage: test
       services:
         - docker:dind
       tags:
         - docker-executor
       script:
         - docker run --rm NAME_OF_IMAGE sh -c "TEST_COMMAND_TO_RUN"
    
     deploy:
       stage: deploy
       tags:
         - my_shell_runner
       script:
         - COMMAND_TO_RUN
         - COMMAND_TO_RUN
         - COMMAND_TO_RUN
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      • 2017-12-29
      • 2021-08-10
      • 2021-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多