如何在使用 forfiles 时出现命令错误时使 CI 脚本失败?

How to fail CI script in case of command error when using forfiles?

我有以下 appveyor.yml 文件:

test_script:
- forfiles /m *.mqh /c "mql /s @path"
build: off
platform: x86

旨在检查在当前目录中找到的所有源代码文件的语法 (/s)。

然而,尽管存在编译错误,但最终结果报告为:构建成功

如何使用上述方法使测试脚本失败?


我在 Linux 上寻找类似于 set -e 的内容。编译器 returns 1 按预期退出时出错,因为它在 Linux 上与 wine 一起使用时工作正常。但是整个构建脚本并没有像预期的那样失败。

AppVeyor 很高兴,因为整个命令 return 代码是 0。我认为它是 return 代码是 0,因为上次迭代很高兴。我不确定如何使其成为 return 错误,以防它至少一次迭代因 forfiles 而失败,但对于 PowerShell 这应该有效:

test_script: - ps: $mqlScriptSuccess = $true - ps: Get-ChildItem | ForEach-Object {if ($_.Name.EndsWith(".mqh")){.\mql /s /mql$env:ver $_.FullName; if(!$?){$mqlScriptSuccess = $?; Write-Warning "mlq error"}}} - ps: if (!$mqlScriptSuccess) {throw "At least one mql test failed"}

请注意,您还可以将 Get-ChildItem 更改为 Get-ChildItem -Recurse 以获得更深入的覆盖范围。