无法在 Team City 中运行基本的 Powershell 脚本 [英] Can't get basic Powershell script running inside Team City

查看:46
本文介绍了无法在 Team City 中运行基本的 Powershell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的配置:

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

On the build log, I only see the output of the first two lines, and then "Process exited with code 0" as the last output of this build step.

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

I tried opening a terminal in the build server in the SYSTEM account (using PsTools), since Team City is configured to run under said account. Then, I created a Test.ps1 file with the same content and ran a command just like Team City's:

[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%

(当然,.ps1 文件的路径和 cmd.exe 初始部分除外).看到前两行的输出,然后终端一下子就消失了!

(except for the path to the .ps1 file and the cmd.exe initial part, of course). I saw the output of the two first lines, and then the terminal disappeared all of a sudden!

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

Where did I mess up? I'm new to Powershell, by the way.

推荐答案

Powershell 的 stdin 命令选项在类似这样的多行命令方面有些奇怪.

The stdin command option of Powershell has some weirdness around multiline commands like that.

您可以使用以下形式的脚本:

You script in the following form would work:

write-host "test"
write-host "test2"
if("1" -eq "1"){write-host "test3 in if"} else {write-host "test4 in else"}

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

The ideal way would be to use the Script : File option in TeamCity which will will run the script you specify using the -File parameter to Powershell.

如果您不想拥有文件和 VCS,在当前设置中,将 Script Execution Mode 更改为 Execute .ps1 file with -File argument.

If you don't want to have a file and having VCS, in the current setup, change Script Execution Mode to Execute .ps1 file with -File argument.

这篇关于无法在 Team City 中运行基本的 Powershell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆