Skip to content

Commit

Permalink
Refactor PowerShell execution script to support pwsh input
Browse files Browse the repository at this point in the history
  • Loading branch information
FH-Inway committed Jan 7, 2024
1 parent 64151eb commit be56147
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tasks/powershell/execute-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit be56147

Please sign in to comment.