5

I want to run CI pipline with 2 jobs:

  1. job will boot up a docker image with docker-runner and run test inside docker
  2. will run under ssh runner and pull code on a remote server.

Is it possible?

2 Answers 2

10

Yes, it's possible. You need to:

  1. Register two GitLab Runners with needed executor (docker and shell), each witch different tag (or, at least one of them with a build tag).
  2. Declare a specific tag for given job in your .gitlab-ci.yml, .

Shell runner registration:

[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 runner registration:

[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...'
2
  • Do these two runners share the same config.toml file? Commented Jul 1, 2020 at 17:14
  • Yes, the same config file. Commented Jul 1, 2020 at 21:19
1

Yes you can trigger different/mixed runners from a single gitlab-ci pipeline.

First you should register a shell runner on the target host and give it a tag (truncated):

$ 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

Within your gitlab-ci.yaml something like this should work. The 'test' job runs your test command in a docker container based on the image NAME_OF_IMAGE.

If that succeeds, the 'deploy' job chooses your shell runner based on the tag 'my_shell_runner' and will execute all commands within the script tag on the runner's host (truncated):

 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.