无法在Team City中运行基本的Powershell脚本

dar*_*mos 13 powershell teamcity powershell-1.0

这是我的配置: 在此输入图像描述

在构建日志中,我只看到前两行的输出,然后"使用代码0退出进程"作为此构建步骤的最后一个输出.

我尝试在SYSTEM帐户的构建服务器中打开终端(使用PsTools),因为Team City配置为在所述帐户下运行.然后,我创建了一个具有相同内容的Test.ps1文件,并像Team City一样运行命令:

[Step 1/4] Starting: C:\Windows\system32\cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -Command - <C:\TeamCity\buildAgent\temp\buildTmp\powershell5129275380148486045.ps1 && exit /b %ERRORLEVEL%
Run Code Online (Sandbox Code Playgroud)

(当然,除了.ps1文件和cmd.exe初始部分的路径之外).我看到了两个第一行的输出,然后终端突然消失了!

我在哪里搞砸了?顺便说一句,我是Powershell的新手.

man*_*lds 19

Powershell的stdin命令选项对于这样的多行命令有一些奇怪之处.

您使用以下格式编写脚本:

write-host "test"
write-host "test2"
if("1" -eq "1"){write-host "test3 in if"} else {write-host "test4 in else"}
Run Code Online (Sandbox Code Playgroud)

理想的方法是使用Script : FileTeamCity中的选项,该选项将使用-FilePowershell参数运行您指定的脚本.

如果您不想拥有文件并拥有VCS,请在当前设置中更改Script Execution ModeExecute .ps1 file with -File argument.

  • @dario_ramos - 发生在powershell 3.0 CTP :) (2认同)