Gitlab-runner register with --*-args not properly handled?

the gitlab-runner register command do all we need without writing config files. But when I see Autoscaling GitLab CI on AWS Fargate | GitLab the file is created by hand. Because I use different runner, I would like to register multiple one. But it seems impossible to pass several argument to gitlab-runner

here is an example (/usr/share/gitlab-runner/runner_template.toml is common to all my runner)

  gitlab-runner register \
    --template-config /usr/share/gitlab-runner/runner_template.toml \
    --name "XXX" \
    --non-interactive \
    --url "<some url>" \
    --registration-token "<my registration token>" \
    --builds-dir /opt/gitlab-runner/builds/XXX/ \
    --cache-dir /opt/gitlab-runner/cache/XXX/ \
    --run-untagged="true" \
    --locked="true" \
    --executor "custom" \
    --custom-config-exec /usr/local/bin/gitlab-runner-fargate \
    --custom-config-args --config /etc/gitlab-runner/driver_fargate.toml custom config \
    --custom-prepare-exec /usr/local/bin/gitlab-runner-fargate \
    --custom-prepare-args --config /etc/gitlab-runner/driver_fargate.toml custom prepare \
    --custom-run-exec /usr/local/bin/gitlab-runner-fargate \
    --custom-run-args --config /etc/gitlab-runner/driver_fargate.toml custom run \
    --custom-cleanup-exec /usr/local/bin/gitlab-runner-fargate \
    --custom-cleanup-args --config /etc/gitlab-runner/driver_fargate.toml custom cleanup

I try to add bracket, quote, … it never succeed to create the file with the proper parameters

  1. Is it required to create multiple template to handle several parameters? Is it a bug? Did I miss something?

  2. Except directly using the api of gitlab (and then create the config file ourselve), is there another way to have the register token?


1 Like

for information, temporary, I solve this issue with multiple template.

I had a similar issue that I wanted to avoid modifying the config.toml file as I was using ansible to script the runner registration.

I found that adding multiple arguments addressed it for me:

The command (ansible task but you can see the syntax):

  - name: register the fargate runner
    command: >-
      --executor "custom"
      --url "{{server_url}}"
      --registration-token "{{server_token}}"
      --description "fargate-runner"
      --tag-list "fargate-runner"
      --custom-config-exec "/opt/gitlab-runner/fargate"
      --custom-config-args "--config"
      --custom-config-args "/etc/gitlab-runner/fargate.toml"
      --custom-config-args "custom"
      --custom-config-args "config"
      --custom-prepare-exec "/opt/gitlab-runner/fargate"
      --custom-prepare-args "--config"
      --custom-prepare-args "/etc/gitlab-runner/fargate.toml"
      --custom-prepare-args "custom"
      --custom-prepare-args "prepare"
      --custom-run-exec "/opt/gitlab-runner/fargate"
      --custom-run-args "--config"
      --custom-run-args "/etc/gitlab-runner/fargate.toml"
      --custom-run-args "custom"
      --custom-run-args "run"
      --custom-cleanup-exec "/opt/gitlab-runner/fargate"
      --custom-cleanup-args "--config"
      --custom-cleanup-args "/etc/gitlab-runner/fargate.toml"
      --custom-cleanup-args "custom"
      --custom-cleanup-args "cleanup"
      --builds-dir "/opt/gitlab-runner/builds"
      --cache-dir "/opt/gitlab-runner/cache"
    when: list_output.stderr.find('fargate-runner') == -1

The resulting section of config.toml:

    config_exec = "/opt/gitlab-runner/fargate"
    config_args = ["--config", "/etc/gitlab-runner/fargate.toml", "custom", "config"]
    prepare_exec = "/opt/gitlab-runner/fargate"
    prepare_args = ["--config", "/etc/gitlab-runner/fargate.toml", "custom", "prepare"]
    run_exec = "/opt/gitlab-runner/fargate"
    run_args = ["--config", "/etc/gitlab-runner/fargate.toml", "custom", "run"]
    cleanup_exec = "/opt/gitlab-runner/fargate"
    cleanup_args = ["--config", "/etc/gitlab-runner/fargate.toml", "custom", "cleanup"]