2

Im trying to run some PS scripts using the Powershell Runner in TC and defining my own script as "Source Code" instead of a script file. My script is as simple as:

"Hello World!"

Im running on Windows Server 2008 R2 and ive tried with to:

  1. Run it as x86 + x64
  2. Using "Execute .ps1 with '-File' argument" + "Put script into powershell stdin with "-Command -" arguments.
  3. Ive set the security policy to Unrestricted in an attempt to get it to work, but no luck.

If I instead use a Command Line runner and for example writes:

powershell -Command Get-ExecutionPolicy

It works fine.

The errors im getting (depending on which of the 2 execution modes im using) are:

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, 

It looks to me like TC puts something in the actual script itself, but im not sure. Im stuck and I cant figure out what point im missing here :S.

Can anyone help?

Christian Mikkelsen
  • 1,661
  • 2
  • 19
  • 44
  • See also http://stackoverflow.com/questions/9165658/cant-get-basic-powershell-script-running-inside-team-city (Hit this first with my search keyworkds but real issue is that put into stdin mode chokes on some things, e.g., if blocks in TC 7.0) – Ruben Bartelink Apr 10 '12 at 10:07

1 Answers1

4

I wasn't able to reproduce this, but I noticed something pretty weird with the command that TeamCity was trying to run:

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

I did not see it adding the quotes for me, so I thought maybe TeamCity is trying to quote a path with space(s) in it ( would have helped if you hadn't redacted your path)

So I switched my agent to a path with a space in it and I got the same command, and yes, the same error. So TeamCity is quoting the path wrongly. It is including the < in the quotes while it should have been <"c:\path with\space"

I will see if I can file a bug for this ( if there isn't one)

Try moving your agent to a non-space path as a workaround.

manojlds
  • 290,304
  • 63
  • 469
  • 417