2012-05-04 61 views
19

这听起来像一个简单的问题,但在查看联机后我无法解决。我基本上想要在Jenkins中执行powershell脚本(例如script.ps1)并报告成功/失败。如何在Jenkins中运行PowerShell脚本作为工作

尝试1:运行以下称为 “执行Windows批处理命令”

powershell -File c:\scripts\script.ps1 

这将启动为预期,但退出几秒钟后

尝试2:运行以下为“执行Windows批处理命令“

powershell -NoExit -File c:\scripts\script.ps1 

这将成功运行整个脚本,但ne Ver停止。我不得不手动中止脚本

回答

27

那么,有一个PowerShell插件,无论如何是包装外壳。我在我的服务器上使用它,以标准符号执行脚本:

powershell -File test001.ps1 

它没有任何怪癖。

+0

很酷,我试过插件,但无法运行ps1文件。但我从未尝试过上述符号。这样试试吧,谢谢! – Danish

+2

我使用了以下内容: powershell -ExecutionPolicy无限制-File file.ps1 –

+1

我无法使插件正常工作,可能与执行策略有关。必须回退到powershell.exe的标准命令行-ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File script.ps1 – Benoit

相关问题