使用forfiles时如何在命令错误的情况下使CI脚本失败?

时间:2017-01-08 21:57:46

标签: windows batch-file appveyor

我有以下appveyor.yml文件:

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

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

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

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

我在Linux上看起来与set -e类似。编译器在退出时会按预期返回1错误,因为它在Linux上使用wine时工作正常。但整个构建脚本并没有像预期的那样失败。

1 个答案:

答案 0 :(得分:1)

AppVeyor很高兴,因为整个命令返回代码为0.我认为它的返回代码为0,因为上一次迭代很开心。我不知道如果使用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以获得更深入的报道。