Skip to content

Allow custom executor to specify the shell used

What does this MR do?

Allows configuring the shell used by a custom executor in the dynamic configuration step.

Why was this MR needed?

Currently, a given custom executor runner can only ever use a single type of shell. We have a custom executor whose job is to setup VMs in a kubevirt cluster. The way it works is simple: A user defines a job as so:

jobname:
    tag: kubevirt-runner
    env:
        KUBEVIRT_TEMPLATE: name-of-template

The runner will use the KUBEVIRT_TEMPLATE to create a new VM based on that template name, run the CI, and finally delete the VM.

The problem is, we have different templates, running in different OSes, and thus needing different shells: Some use cmd, others bash. In the current gitlab-runner, however, a given executor may only work with a single shell, hardcoded in its config.toml. As such, it is not possible to configure the shell dynamically based on the KUBEVIRT_TEMPLATE.

This makes the user-experience less ideal, as the user has to set a different tag depending on the shell they want to use.

What's the best way to test this MR?

Try the following runner:

config.sh:

#!/usr/bin/env bash
echo '{"shell":"pwsh"}'

run.sh:

#!/usr/bin/env bash
pwsh $1

config.toml:

concurrent = 50
check_interval = 0
[session_server]
  session_timeout = 1800
[[runners]]
  name = "custom-runner"
  url = "https://gitlab.com/"
  token = "<TOKEN>"
  executor = "custom"
  builds_dir = "/tmp/gitlab-runner/builds"
  cache_dir = "/tmp/gitlab-runner/cache"
  [runners.custom]
    config_exec = "config.sh"
    run_exec = "run.sh"

With this MR, run.sh's first argument will be a powershell script that can be ran through powershell.

What are the relevant issue numbers?

gitlab#375586 (closed)

Edited by Robin Lambertz

Merge request reports