2

I'm running a PowerShell script as one of the post-build steps in TeamCity and at one point I'm trying to create an empty file as a place-holder for a later step. The code I started with was:

New-Item $MyPathAndFileName -Force

This worked fine on my machine in the ISE. However executing it in TeamCity causes the whole build step (and therefore the build configuration) to fail with a build log entry of:

Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available.

I've then appended to my code to end up at the following:

if((Test-Path $MyPathAndFileName) -ne 0)
    {Remove-Item $MyPathAndFileName -Force}
New-Item $$MyPathAndFileName -Force -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -InformationAction SilentlyContinue

It's always the New-Item line that fails.

My question is can I either

a) get PowerShell to write out what the prompt it is trying to display so I can fault-find what is wrong?, or

b) create the new item without a prompt?

GavTheGuru
  • 51
  • 7
  • Is it possible that the account teamcity is running under does not have permissions? – TravisEz13 Jan 23 '17 at 23:02
  • I can see the point of your question, but other parts of the same script and the actual compile step of the build configration are already writing to the folder in question – GavTheGuru Jan 23 '17 at 23:16
  • Have you tried adding `-confirm:$false` as suggested [here](http://stackoverflow.com/questions/16580723/powershell-in-noninteractive-mode)? – sarbis Jan 24 '17 at 08:15

1 Answers1

3

In this instance, it turns out that one of the Agents on our TeamCity Server was running an older version of PowerShell and was expecting the -Type parameter to name "file". This worked for that line but then that agent had issues with a later script line that was dealing with zip files.

As we were unable to upgrade the PowerShell version we set a temporary work-around as a Build Configuration, Agent Requirement to name the specific Agent needed to successfully run the build.

The bottom-line, though, is that the problem of PowerShell executing on a TeamCity server and trying to prompt the user prevails. A method to write the prompt to the Build Log would facilitate intelligent fault-finding.

Thank you for the responses.

GavTheGuru
  • 51
  • 7