Reputation: 3798
This sounds like a simple question, but I haven't been able to work it out after looking online. I basically want to execute a PowerShell script (e.g. script.ps1) in Jenkins and report success/failure.
Try 1: Run following as "Execute Windows Batch Command"
powershell -File c:\scripts\script.ps1
This starts up as expected, but it quits after a few seconds.
Try 2: Run following as "Execute Windows Batch Command"
powershell -NoExit -File c:\scripts\script.ps1
This runs the whole script successfully, but it never stops. I had to manually abort the script.
Upvotes: 29
Views: 62827
Reputation: 11
If you are facing issue on Windows machine while executing shell script using Jenkins then refer below steps -
powershell.exe -ExecutionPolicy Bypass -File "C:\TEMP\deleteFile.ps1"
make sure to replace "C:\TEMP\deleteFile.ps1" with your PowerShell script file path.
Upvotes: 0
Reputation: 173
If you run the 64 bit PowerShell you don't need run the '-ExecutionPolicy Bypass':
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -nologo -file 'c:\scripts\upgrade-Chrome.ps1' -WindowStyle Hidden
Upvotes: 0
Reputation: 433
I found the problem came down to PowerShell managing the execution policy separately for 32-bit and 64-bit versions. Checkout http://www.gregorystrike.com/2011/01/27/how-to-tell-if-powershell-is-32-bit-or-64-bit/ to try launching both. Run Get-ExecutionPolicy
in both and you will see they are different.
At least with version 1.4, it appears the plugin ends up using the 32-bit process.
Upvotes: 7
Reputation: 5836
Well, there is a PowerShell plugin, which is wrapping the shell anyway. I use this on my server, executing scripts in standard notation:
powershell -File test001.ps1
It works without any quirks.
Upvotes: 34