Powershell – How to run a PowerShell script as a job in Jenkins

Jenkinspowershellpowershell-2.0

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.

Best Answer

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.