From be56147821beb15386f958bd3c8105f6ec0b7d23 Mon Sep 17 00:00:00 2001 From: Florian Hopfner <33372796+FH-Inway@users.noreply.github.com> Date: Sun, 7 Jan 2024 12:55:23 +0000 Subject: [PATCH] Refactor PowerShell execution script to support pwsh input --- tasks/powershell/execute-cli.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tasks/powershell/execute-cli.ts b/tasks/powershell/execute-cli.ts index b0e7d1e..a6666c7 100644 --- a/tasks/powershell/execute-cli.ts +++ b/tasks/powershell/execute-cli.ts @@ -40,6 +40,7 @@ async function run() { const input_failOnStderr = tl.getBoolInput('failOnStderr', false); const input_ignoreLASTEXITCODE = tl.getBoolInput('ignoreLASTEXITCODE', false); const input_workingDirectory = tl.getPathInput('workingDirectory', /*required*/ true, /*check*/ true); + const input_pwsh: boolean = tl.getBoolInput('pwsh', false); let input_filePath: string; let input_arguments: string; @@ -111,15 +112,22 @@ async function run() { // Run the script. // - // Note, prefer "pwsh" over "powershell". At some point we can remove support for "powershell". + // Note, prefer "powershell" over "pwsh" unless the pwsh input is true. // // Note, use "-Command" instead of "-File" to match the Windows implementation. Refer to // comment on Windows implementation for an explanation why "-Command" is preferred. console.log('========================== Starting Command Output ==========================='); const executionOperator = input_runScriptInSeparateScope ? '&' : '.'; - const powershell = tl.tool(tl.which('pwsh') || tl.which('powershell') || tl.which('pwsh', true)) - .arg('-NoLogo') + + let powershell: tr.ToolRunner; + if (input_pwsh) { + powershell = tl.tool(tl.which('pwsh') || tl.which('powershell') || tl.which('pwsh', true)); + } else { + powershell = tl.tool(tl.which('powershell') || tl.which('pwsh') || tl.which('powershell', true)); + } + + powershell.arg('-NoLogo') .arg('-NoProfile') .arg('-NonInteractive') .arg('-Command')