我正在尝试在Maven构建中运行PowerShell脚本,但我看到了以下错误。
[INFO] --- exec-maven-plugin:1.6.0:exec (import) @ test-build ---
D:\Jenkins\workspace\test-build\Build\file.ps1 : File
D:\Jenkins\workspace\test-build\Build\file.ps1 cannot be loaded
because running scripts is disabled on this system. For more information, see
about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ D:\Jenkins\workspace\test-build\Build\file.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
[ERROR] Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
我看过这个问题的回答,建议你添加参数
Set-ExecutionPolicy RemoteSigned -Force
或
Set-ExecutionPolicy Unrestricted
但我不知道在哪里添加这个。 这会直接添加到.ps1文件吗?
Called by Maven in Compile Phase
Set-ExecutionPolicy Unrestricted -Force
或
<executions>
<execution>
...
<configuration>
...
<executable>PowerShell.exe</executable>
<arguments>
<argument>XYZ\file.ps1</argument>
<argument>-ExecutionPolicy Bypass</argument>
</arguments>
</configuration>
</execution>
提前感谢您提供反馈和/或