diff --git a/releaseNote.md b/releaseNote.md index b442870a4..723e30b7f 100644 --- a/releaseNote.md +++ b/releaseNote.md @@ -1,5 +1,6 @@ ## Features - Set Default shell to powershell for windows runners (#135) + - Use Powershell as fallback if Powershell Core is not available for default shell on windows (#142) ## Bugs - Removed unintended additional fields on error and warning commands (#137) diff --git a/src/Runner.Worker/Handlers/ScriptHandler.cs b/src/Runner.Worker/Handlers/ScriptHandler.cs index 182913049..6564863a6 100644 --- a/src/Runner.Worker/Handlers/ScriptHandler.cs +++ b/src/Runner.Worker/Handlers/ScriptHandler.cs @@ -60,10 +60,16 @@ namespace GitHub.Runner.Worker.Handlers if (string.IsNullOrEmpty(shell)) { #if OS_WINDOWS - shellCommand = "powershell"; + shellCommand = "pwsh"; if(validateShellOnHost) { - shellCommandPath = WhichUtil.Which(shellCommand, true, Trace); + shellCommandPath = WhichUtil.Which(shellCommand, require: false, Trace); + if (string.IsNullOrEmpty(shellCommandPath)) + { + shellCommand = "powershell"; + Trace.Info($"Defaulting to {shellCommand}"); + shellCommandPath = WhichUtil.Which(shellCommand, require: true, Trace); + } } #else shellCommand = "sh"; @@ -143,8 +149,14 @@ namespace GitHub.Runner.Worker.Handlers if (string.IsNullOrEmpty(shell)) { #if OS_WINDOWS - shellCommand = "powershell"; - commandPath = WhichUtil.Which(shellCommand, true, Trace); + shellCommand = "pwsh"; + commandPath = WhichUtil.Which(shellCommand, require: false, Trace); + if (string.IsNullOrEmpty(commandPath)) + { + shellCommand = "powershell"; + Trace.Info($"Defaulting to {shellCommand}"); + commandPath = WhichUtil.Which(shellCommand, require: true, Trace); + } ArgUtil.NotNullOrEmpty(commandPath, "Default Shell"); #else shellCommand = "sh";