Skip to content

Only default to Powershell on Windows if no other shell is specified

Elliot Rushton requested to merge allow-specifying-cmd-shell into master

What does this MR do?

(Re)allows the user to specify using cmd as the shell type when registering in non-interactive mode instead of always defaulting them to Powershell.

Why was this MR needed?

In !1406 (merged) the default shell when using the shell executor under Windows was set to Powershell, but this accidentally had the side effect of overriding when a user specifies using a different shell type such as batch/cmd.

Are there points in the code the reviewer needs to double check?

It's a simple change but I wasn't sure if there was a good way to add a test for it. I've tested it manually as follows.

Specifying the shell:

C:\Users\vagrant\go\src\gitlab.com\gitlab-org\gitlab-runner>go run main.go register --name "windows-cmd-for-shell-plz" --non-interactive --url "https://gitlab.com" --registration-token "xyz" --executor "shell" --shell "cmd"
Config file var set at: C:\Users\vagrant\go\src\gitlab.com\gitlab-org\gitlab-runner\config.toml
Runtime platform                                    arch=amd64 os=windows pid=5912 revision=HEAD version=development version
Registering runner... succeeded                     runner=xyz
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

which results in the following config.toml

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "windows-cmd-for-shell-plz"
  url = "https://gitlab.com"
  token = "xyz"
  executor = "shell"
  shell = "cmd"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
  [runners.custom]
    run_exec = ""

and not specifying the shell and using the default:

C:\Users\vagrant\go\src\gitlab.com\gitlab-org\gitlab-runner>go run main.go register --name "default-shell-for-shell-plz" --non-interactive --url "https://gitlab.com" --registration-token "xyz" --executor "shell"
Config file var set at: C:\Users\vagrant\go\src\gitlab.com\gitlab-org\gitlab-runner\config.toml
Runtime platform                                    arch=amd64 os=windows pid=1912 revision=HEAD version=development version
Registering runner... succeeded                     runner=xyz
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

which results in the following config.toml

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800
  
[[runners]]
  name = "default-shell-for-shell-plz"
  url = "https://gitlab.com"
  token = "xyz"
  executor = "shell"
  shell = "powershell"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
  [runners.custom]
    run_exec = ""

Does this MR meet the acceptance criteria?

  • Documentation created/updated
  • Added tests for this feature/bug
  • In case of conflicts with master - branch was rebased

What are the relevant issue numbers?

#4456 (closed)

Merge request reports