garden-io / garden

Automation for Kubernetes development and testing. Spin up production-like environments for development, testing, and CI on demand. Use the same configuration and workflows at every step of the process. Speed up your builds and test runs via shared result caching
https://garden.io
Mozilla Public License 2.0
3.4k stars 275 forks source link

[Bug]: Exec action `spec.shell` does not accept a shell specified as a string #6576

Open WillDaSilva opened 1 month ago

WillDaSilva commented 1 month ago

Bug

Current behavior

The documentation for spec.shell for every kind of exec action says:

If true, runs file inside of a shell. Uses `/bin/sh` on UNIX and `cmd.exe` on Windows. A different shell can be specified as a string. The shell should understand the `-c` switch on UNIX or `/d /s /c` on Windows.

Expected behavior

It's unclear where/how "a different shell can be specified as a string". This issue is either a documentation bug if this feature – using a different shell – is supported but poorly documented, or a bug in the code if the spec.shell field is meant to accept strings.

Reproducible example

kind: Run
name: mre
type: exec
spec:
  shell: "bash"
  command:
    - >
      echo "your command here"
Error validating spec for Run type=exec name=mre:

At path spec.shell: Expected boolean, received string

Workaround

Use spec.shell: false, and then manually call the alternative shell in spec.command:

spec:
  shell: false
  command:
    - "bash"
    - "-c"
    - >
      echo "your command here"

Suggested solution(s)

Make spec.shell a boolean | string field, and have it interpret string values as the name/path of the shell that will be used. An example added to the documentation would be nice too.

Your environment

garden version: 0.13.42

thsig commented 3 weeks ago

Hi @WillDaSilva! Thanks for reporting this.

We should fix both the docs and the functionality in this case—we should allow shell to be a boolean or a string (with the boolean true using the default shell for the platform, whereas a string would specify the shell to use).

We should also support specifying the command as a string instead of an array.

I'll keep you posted.