在 pwsh 中调用以下命令:
Write-Host '{"drop_attr": "name"}'
Run Code Online (Sandbox Code Playgroud)
结果正常:
{"drop_attr": "name"}
Run Code Online (Sandbox Code Playgroud)
现在通过 pwsh 执行相同操作:
pwsh -Command Write-Host '{"drop_attr": "name"}'
Run Code Online (Sandbox Code Playgroud)
结果缺少引号和方括号?
drop_attr: name
Run Code Online (Sandbox Code Playgroud) 如果程序失败,是否有一个优雅的 Powershell 脚本设置可以退出正在运行的 Powershell 脚本(或 shell 实例)?
我正在想象类似 Bash 功能set -o errexit(或set -e)但用于 Powershell 的东西。在该功能中,如果 bash 脚本中的程序失败(进程返回代码不是0),则 bash shell 实例会立即退出。
在 powershell 中,脚本可以检查$LastExitCode. 但是,对于每个程序调用来说,这变得很麻烦。也许powershell有一个功能可以自动检查程序返回码并做出反应。
Set-Powershell-Auto-Exit 'ProgramReturnCode' # what should this be?
& program.exe --fail # this program fails with an error code
& foo.exe # this never runs because script has exited
Run Code Online (Sandbox Code Playgroud) 我的 azure 管道和我的一台服务器有问题。
失败的服务器是 Windows 2019 服务器。
如果我在 powershell 中调用 git,那么它会将所有警告和以下行视为错误。如果我在两台不同的服务器上做同样的事情 - 没有问题 - 即使输出相同。
这是返回的错误:
CD to D:\web\test\testsite.com
##[error]git : Warning: Permanently added the RSA host key for IP address 'X' to the list of known hosts.
##[error]git : From bitbucket.org:SITE
##[error]At C:\azagent\A1\_work\_temp\c1ff2d2b-c773-4adc-9040-155e92a914bd.ps1:12 char:1
+ git pull origin master
+ ~~~~~~~~~~~~~~~~~~~~~~
##[error] + CategoryInfo : NotSpecified: (From bitbucket....b/fletcocarpets:String) [], RemoteException
##[error] + FullyQualifiedErrorId : NativeCommandError
##[error]
##[error]PowerShell exited with code '1'.
Run Code Online (Sandbox Code Playgroud)
Git 确实进行了拉动,实际上一切正常。但出于某种原因 - 在此服务器上 - azure 管道将文本视为错误。
任何想法为什么?很难在文本上正确解释问题。 …