如何在Jenkins中运行PowerShell脚本作为工作

时间:2012-05-04 16:44:56

标签: powershell jenkins powershell-v2.0

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

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

powershell -File c:\scripts\script.ps1 

这会按预期启动,但会在几秒后退出

尝试2:以“执行Windows批处理命令”

运行以下命令
powershell -NoExit -File c:\scripts\script.ps1

这会成功运行整个脚本,但永远不会停止。我不得不手动中止脚本

2 个答案:

答案 0 :(得分:28)

好吧,有一个PowerShell插件,无论如何都要包装shell。我在我的服务器上使用它,以标准表示法执行脚本:

powershell -File test001.ps1

它没有任何怪癖。

答案 1 :(得分:5)

我发现问题归结为PowerShell分别为32位和64位版本管理执行策略。结帐http://www.gregorystrike.com/2011/01/27/how-to-tell-if-powershell-is-32-bit-or-64-bit/尝试启动两者。在两者中运行Get-ExecutionPolicy,你会发现它们是不同的。

至少在版本1.4中,看起来插件最终使用32位进程。