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

编程入门 行业动态 更新时间:2024-10-26 19:29:34
本文介绍了无法在 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 脚本

本文发布于:2023-11-17 05:33:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609008.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   Team   City   Powershell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!