'How to run a PowerShell script as a job in Jenkins
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.
Solution 1:[1]
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.
Solution 2:[2]
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.
Solution 3:[3]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ?ukasz R?anek |
| Solution 2 | Adam Hewitt |
| Solution 3 | Patrick Burwell |
