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

Dan*_*ish 22 powershell powershell-2.0 jenkins

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

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

powershell -File c:\scripts\script.ps1
Run Code Online (Sandbox Code Playgroud)

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

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

powershell -NoExit -File c:\scripts\script.ps1
Run Code Online (Sandbox Code Playgroud)

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

Łuk*_*nek 28

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

powershell -File test001.ps1
Run Code Online (Sandbox Code Playgroud)

它没有任何怪癖.

  • 我使用了以下内容:powershell -ExecutionPolicy Unrestricted -File file.ps1 (3认同)

Ada*_*itt 7

我发现问题归结为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位进程.