TeamCity Powershell Runner - 无法运行源代码

时间:2012-02-09 20:01:38

标签: powershell teamcity

我试图在TC中使用Powershell Runner运行一些PS脚本,并将我自己的脚本定义为“源代码”而不是脚本文件。 我的脚本很简单:

"Hello World!"

我在Windows Server 2008 R2上运行,并尝试过:

  1. 以x86 + x64
  2. 运行它
  3. 使用“执行带有'-File'参数的.ps1”+“将脚本放入带有”-Command - “参数的powershell stdin中。
  4. 我已将安全策略设置为Unrestricted以试图让它工作,但没有运气。
  5. 如果我改为使用命令行运行器,例如写:

    powershell -Command Get-ExecutionPolicy
    

    工作正常。

    我得到的错误(取决于我使用的2种执行模式中的哪一种)是:

    Starting: C:\...\cmd.exe /c C:\...\powershell.exe -NonInteractive -Command 
    - "<C:\...\powershell3889347351955805274.ps1" && exit /b %ERRORLEVEL%
    in directory: C:\...\e18dda4054c166c7
    '-' was specified with the -Command parameter; no other arguments to -Command are permitted.
    

    OR

    Starting: C:\...\cmd.exe /c C:\...\powershell.exe -NonInteractive -File     
    "C:\...\powershell8264270201473986040.ps1" && exit /b %ERRORLEVEL%
    in directory: C:\...\e18dda4054c166c7
    The term 'f' is not recognized as the name of a cmdlet, function, script file, 
    

    在我看来,TC就像实际脚本本身一样,但我不确定。我陷入了困境,我无法弄清楚我在这里缺少什么:S。

    有人可以帮忙吗?

1 个答案:

答案 0 :(得分:4)

我无法重现这一点,但我注意到TeamCity试图运行的命令有些奇怪:

-NonInteractive -Command - "<C:\...\powershell3889347351955805274.ps1"

我没有看到它为我添加引号,所以我想也许TeamCity试图引用一个带有空格的路径(如果你没有编辑你的路径会有帮助)

所以我将我的代理切换到一个带有空格的路径,我得到了相同的命令,是的,同样的错误。所以TeamCity错误地引用了这条路径。它包含引号中的<,而它应该是<"c:\path with\space"

我会看看我是否可以为此提交错误(如果没有错误)

尝试将代理移动到非空间路径作为解决方法。