Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

teamcity - Can't get basic Powershell script running inside Team City

Here's my configuration: enter image description here

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.

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:Windowssystem32cmd.exe /c C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -NonInteractive -Command - <C:TeamCityuildAgentempuildTmppowershell5129275380148486045.ps1 && exit /b %ERRORLEVEL%

(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!

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"}

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...