如何在 Jenkins 的作业中执行 powershell 文件?

How execute a powershell file in a job from Jenkins?

在配置作业中,我有这个:

但是,我在执行作业时遇到下一个错误:

.ps1 cannot be loaded because the
 execution of scripts is disabled on this system. Please see "get-help about_si
gning" for more details.
At line:1 char:2
+ & <<<<  'C:\Windows\TEMP\abc.ps1'
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException

Build step 'Windows PowerShell' marked build as failure
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: FAILURE

我认为这是因为我的 Jenkins 实例不是管理员。

注:

- I have a instance of Jenkins in my machine local
- And when I compile from my  windows power shell console, this if execute (This is possible with this instruction "Set-ExecutionPolicy Unrestricted")

您需要在服务器上设置执行策略。 您可以通过在您的 powershell 中输入以下内容来设置执行策略 window:

Set-ExecutionPolicy RemoteSigned

更多详情https://technet.microsoft.com/en-us/library/ee176961.aspx

不要运行 Jenkins 服务器使用服务... 运行 cmd 中的jenkin 服务器window(没有window 服务)