Search code examples
powershelljenkinsjenkins-pipelinedevops

Jenkins PowerShell: Start-Process with Passthru returns a different process ID when executed in Jenkins but not on PowerShell


I'm experiencing a weird scenario where I want to open a .rdp file and get its Process ID on a Jenkins Pipeline.

My PowerShell Script (which based from this answer):

$app = Start-Process "$env:windir\system32\mstsc.exe" -ArgumentList "C:\Users\AzureUser\Desktop\MyRDP.rdp /h:900 /w:1600" -WindowStyle Minimized -PassThru

Write-Host $app.id

When I ran this on PowerShell it works as expected. However, when I tried to execute this script on a Jenkins Pipeline, it opens the .rdp file but returns a different process ID.

Here's the screenshot of the result.

I also tried enclosing it in an Invoke-Command to make sure that it runs on a 64-bit Powershell but it did not change a thing.

I'm wondering what might be the other possible cause of this. Any help is going to be appreciated. :)


Solution

  • The solution is just simple. I will post my answer anyway incase anyone might encounter the same problem I have. You just need to make sure that Jenkins runs on 64-bit. That's all and worked like a charm.