我正在运行PowerShell脚本作为TeamCity中的后构建步骤之一,并且我正在尝试创建一个空文件作为后续步骤的占位符 . 我开始的代码是:
New-Item $MyPathAndFileName -Force
这在我的ISE机器上运行良好 . 但是,在TeamCity中执行它会导致整个构建步骤(以及构建配置)失败,并且构建日志条目为:
Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available.
然后我附加到我的代码,最终得到以下结果:
if((Test-Path $MyPathAndFileName) -ne 0)
{Remove-Item $MyPathAndFileName -Force}
New-Item $$MyPathAndFileName -Force -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -InformationAction SilentlyContinue
它始终是New-Item系列失败 .
我的问题也可以
a)让PowerShell写出它试图显示的提示,这样我就可以错误地找到错误了吗?或者
b)没有提示创建新项目?
1 回答
在这个例子中,事实证明我们的TeamCity Server上的一个代理正在运行旧版本的PowerShell,并期望-Type参数命名为“file” . 这适用于该行,但后来该代理与稍后处理zip文件的脚本行有问题 .
由于我们无法升级PowerShell版本,因此我们将临时解决方案设置为构建配置,代理要求,以命名成功运行构建所需的特定代理 .
但最重要的是,PowerShell在TeamCity服务器上执行并尝试提示用户的问题占上风 . 将提示写入构建日志的方法将有助于智能故障查找 .
感谢您的回复 .