Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

override shell used for step scripts #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions engine/compiler/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ func setupScript(src *resource.Step, dst *engine.Step, os string) {
// helper function configures the pipeline script for the
// windows operating system.
func setupScriptWindows(src *resource.Step, dst *engine.Step) {
dst.Entrypoint = []string{"powershell", "-noprofile", "-noninteractive", "-command"}
sh := "powershell"
if len(src.Shell) != 0 {
sh = src.Shell
}
dst.Entrypoint = []string{sh, "-noprofile", "-noninteractive", "-command"}
dst.Command = []string{"echo $Env:DRONE_SCRIPT | iex"}
dst.Envs["DRONE_SCRIPT"] = powershell.Script(src.Commands)
dst.Envs["SHELL"] = "powershell.exe"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking over the change once more, I realize that maybe we also want to pass the name of the overridden shell to the executing script. Although I am not sure about the role of the file extension here.

Suggested change
dst.Envs["SHELL"] = "powershell.exe"
dst.Envs["SHELL"] = sh

I am also not sure if/where a similar thing is done on the Linux side of things.

Expand All @@ -36,7 +40,11 @@ func setupScriptWindows(src *resource.Step, dst *engine.Step) {
// helper function configures the pipeline script for the
// linux operating system.
func setupScriptPosix(src *resource.Step, dst *engine.Step) {
dst.Entrypoint = []string{"/bin/sh", "-c"}
sh := "/bin/sh"
if len(src.Shell) != 0 {
sh = src.Shell
}
dst.Entrypoint = []string{sh, "-c"}
dst.Command = []string{`echo "$DRONE_SCRIPT" | /bin/sh`}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this shell invocation also use the overridden shell? I am not familiar enough with the script compiler to judge whether this would be a good idea or not.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so looking at what gets eventually gets called is https://github.com/drone/runner-go/blob/0bd0f8fc31c489817572060d17c6e24aaa487470/shell/bash/bash.go#L26

dst.Command = []string{`echo "$DRONE_SCRIPT" | /bin/sh`}

where we pipe the commands into /bin/sh this also needs looked at

dst.Envs["DRONE_SCRIPT"] = shell.Script(src.Commands)
}