arcade icon indicating copy to clipboard operation
arcade copied to clipboard

Cannot use pwsh local tool with arcade

Open jaredpar opened this issue 1 year ago • 2 comments

The implementation of ExitWithExitCode means that we cannot use pwsh as a local tool in our repos. The implementation kills a number of processes, including dotnet. That means when you execute a script with dotnet pwsh example.ps1 the ExitWithExitCode will kill itself.

Example:

. "eng/common/tools.ps1"
$prepareMachine=$true
$ci=$true
ExitWithExitCode 0

Put that script in the root of a repo then execute it:

E:\code\wt\ros3 
⚡🔨 > dotnet pwsh .\example.ps1
Killing running build processes...
E:\code\wt\ros3 
⚡🔨 > $LASTEXITCODE
-1

jaredpar avatar Feb 29 '24 21:02 jaredpar

Probably need to change Stop-Process to be

function Stop-Processes() {
  Write-Host 'Killing running build processes Roslyn style...'
  foreach ($processName in $processesToStopOnExit) {
    Get-Process -Name $processName -ErrorAction SilentlyContinue 
      ? { $_.ProcessId -ne $PID }
      | Stop-Process
  }
}

Really though, why we blanket kill dotnet here? What are we trying to achieve that forces us to do this?

jaredpar avatar Feb 29 '24 21:02 jaredpar

Really though, why we blanket kill dotnet here? What are we trying to achieve that forces us to do this?

I'm not sure of the history but suspect the process clean up is intended to ensure files are released before builds create artefacts.

In any case, there might be a workaround: Your builds could create a variable named processesToStopOnExit that's an array of strings naming what you want stopped. The default is @('msbuild', 'dotnet', 'vbcscompiler'). Passing @('msbuild', 'vbcscompiler') might do the trick for you @jaredpar.

If not, this seems like a quick fix. Feel free to open a PR 😁

dougbu avatar Mar 21 '24 23:03 dougbu