[英]How do I get error codes (Windows) out of the NPM version of JSHint, for CI?
我们刚刚升级到Windows中的NPH版本的JSHint,我们的CI将不再失败JSHint失败。 这感觉就像一个愚蠢的问题,但我无法弄清楚。
我们正在运行NAnt和CCNet。 当我们尝试从NAnt中运行jshint.cmd时,它无法说明路径错误。 我无法对脚本中的路径进行硬编码,因为每个开发站(和CI服务器)都将NPM和JSHint安装在不同的位置(“C:\\ Users \\ me \\ AppData \\ Roaming \\ npm”)。
所以我们编写了一个NAnt调用的批处理文件,它调用了jshint.cmd。 它现在运行JSHint,但不会给出错误代码或正确失败。 看起来我们的批处理文件的末尾在jshint.cmd失败后没有运行,看起来没有为NAnt设置错误级别来检查。 我已经尝试在NAnt中检查resultproperty,但没有运气。
这是一些文件:
JSHint.build
<target name="JSHint">
<exec program="runjshint.cmd" basedir="${jshint.dir}" workingdir="${jshint.dir}">
<arg value="${scripts.dir}" />
</exec>
</target>
runjshint.cmd
jshint --reporter=reporter.js %1
REM Everything past here isn't run.
NAnt输出
[exec] C:\work\ThirdParty\jshint>jshint --reporter=reporter.js ..\..\src\Scripts
[exec]
[exec]
[exec] jshint failed:
[exec]
[exec] ..\..\src\Scripts\app\ViewModels\FakeViewModel.js: line 62, col 31, 'FakeVariable' is not defined.
[exec] ..\..\src\Scripts\app\ViewModels\FakeViewModel.js: line 78, col 33, 'FakeVariable' is not defined.
[exec]
[exec] 2 errors
BUILD SUCCEEDED
请注意,即使JSHint失败,构建也会成功。
我在SO上的另一篇文章中找到了答案: https : //stackoverflow.com/a/10359327/227349
<!--Next arg: forces node's stderror and stdout to a temporary file-->
<arg line=" > _tempfile.out 2<&1"/>
<!--Next arg: If command exits with an error, then output the temporary file to stdout, -->
<!--delete the temporary file and finally exit with error level 1 so that -->
<!--the apply task can catch the error if @failonerror="true" -->
<arg line=" || (type _tempfile.out & del _tempfile.out & exit /b 1)"/>
<!--Next arg: Otherwise, just type the temporary file and delete it-->
<arg line=" & type _tempfile.out & del _tempfile.out &"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.