简体   繁体   中英

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

I've the following appveyor.yml file:

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

which aims to check the syntax ( /s ) of all source code files found in the current directory.

However despite of compiler errors, the final result is reported as: Build success .

How do I fail the test script by using above approach?


I'm looking something similar to set -e on Linux. The compiler returns 1 error on exit as expected, as it works fine when using with wine on Linux. But the whole build script doesn't fail as expected.

AppVeyor happy because whole command return code is 0. I think it's return code is 0 because last iteration was happy. I am not sure how to make it return error in case it least one iteration failed with forfiles , but with PowerShell this should work:

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"}

Note that you can also change Get-ChildItem to Get-ChildItem -Recurse to get deeper coverage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM