代码之家  ›  专栏  ›  技术社区  ›  KS1

pom。xml和PowerShell执行-UnauthorizedAccess错误

  •  0
  • KS1  · 技术社区  · 8 年前

    我试图在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>
    

    0 回复  |  直到 8 年前