-
Notifications
You must be signed in to change notification settings - Fork 88
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
base: master
Are you sure you want to change the base?
Conversation
I just tested it on windows and was able to use both Getting images like |
Hey @julmb thanks for this change, we are concerned about this being mostly un-needed for most cases, as this is the first PR for this. However it is needed for this edge case you found, so we want to merge it. I would like to add some docs for this first, would you have a look over them ? |
Yes, I realize that this is a fairly specific case, especially since not many people seem to be using Drone on Windows. Nonetheless, it would make life easier in this case. It would also provide some future-proofing, as Microsoft looks to be giving the cross-platform I would of course be more than happy to help with documentation. |
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" |
There was a problem hiding this comment.
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.
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.
if len(src.Shell) != 0 { | ||
sh = src.Shell | ||
} | ||
dst.Entrypoint = []string{sh, "-c"} | ||
dst.Command = []string{`echo "$DRONE_SCRIPT" | /bin/sh`} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Here are the docs i created for this drone/docs#495 |
Hey @julmb i spoke with @bradrydzewski about this, and it gets complicated quickly as you have seen particularly on the linux side. After talking around the problem for a bit we came to the conclusion to limit this to the windows side only for now. we can then add a lint check into https://github.com/drone-runners/drone-runner-docker/blob/master/engine/linter/linter.go#L72
what do you think ? |
That sounds reasonable. It is a little unfortunate that it cannot be done in a more general way, but I agree that it is really only needed on Windows, so this should cover the main use cases.
This covers all the use cases I have come across so far. However, I am a little worried that a different shell name might be needed at some point. It would then be very frustrating for users to find out that a feature that solves their problem has already been implemented but artificially restricted to not work for their case. I personally favor warning users about doing questionable things rather than preventing them outright. However, this is a matter of design philosophy, so I will leave that to the Drone developers to decide.
I would be okay with doing things the way you proposed. How do we proceed? Should I adjust the pull request to only cover the Windows side? (I'm new to contributing to FOSS, so I'm not familiar with how things are done). |
This also helps with #13 |
I know it has been a long time, but I am still using my own patched version of |
This change enables overriding the shell that is used to execute the commands in a step. The motivation for this is that the various Windows images provided by Microsoft do not offer a consistent shell. Some provide
powershell
, while others providepwsh
, currently making the latter unusable in pipeline steps. See #34 for more details.After realizing that the proposed changes in #34 were not sufficient, I took a better look at the code. It turns out the drone configuration file format already provides a key
shell
, available asresource.Step.Shell
but not used bydrone-runner-docker
. The proposed change does not alter the behavior of a step unless it contains a keyshell
. If it does, this shell is used instead of the default/bin/sh
andpowershell
, respectively.I have tried it on Linux and will try it on Windows tomorrow.