简体   繁体   English

如何从CI的NPM版本中获取错误代码(Windows)?

[英]How do I get error codes (Windows) out of the NPM version of JSHint, for CI?

We've just upgraded to the NPM version of JSHint in Windows, and our CI won't fail on JSHint failures anymore. 我们刚刚升级到Windows中的NPH版本的JSHint,我们的CI将不再失败JSHint失败。 This feels like a silly problem, but I can't figure it out. 这感觉就像一个愚蠢的问题,但我无法弄清楚。

We're running NAnt and CCNet. 我们正在运行NAnt和CCNet。 When we try to run jshint.cmd from within NAnt, it fails saying that the path is wrong. 当我们尝试从NAnt中运行jshint.cmd时,它无法说明路径错误。 I can't hard code the path in the script because each dev station (and CI server) has NPM and JSHint installed in a different location ("C:\\Users\\me\\AppData\\Roaming\\npm"). 我无法对脚本中的路径进行硬编码,因为每个开发站(和CI服务器)都将NPM和JSHint安装在不同的位置(“C:\\ Users \\ me \\ AppData \\ Roaming \\ npm”)。

So we've written a batch file which NAnt calls, which calls jshint.cmd. 所以我们编写了一个NAnt调用的批处理文件,它调用了jshint.cmd。 It now runs JSHint, but won't give error codes or fail properly. 它现在运行JSHint,但不会给出错误代码或正确失败。 It looks like the end of our batch file is not run after the jshint.cmd fails, and it looks like there is no errorlevel set for NAnt to check against. 看起来我们的批处理文件的末尾在jshint.cmd失败后没有运行,看起来没有为NAnt设置错误级别来检查。 I've tried checking resultproperty in NAnt as well with no luck. 我已经尝试在NAnt中检查resultproperty,但没有运气。

Here's a few files: 这是一些文件:

JSHint.build JSHint.build

<target name="JSHint">
    <exec program="runjshint.cmd" basedir="${jshint.dir}" workingdir="${jshint.dir}">
        <arg value="${scripts.dir}" />
    </exec>
</target>

runjshint.cmd runjshint.cmd

    jshint --reporter=reporter.js %1
    REM Everything past here isn't run.

NAnt output 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

Note that the build succeeded even though JSHint failed. 请注意,即使JSHint失败,构建也会成功。

I found the answer in another post on SO: https://stackoverflow.com/a/10359327/227349 我在SO上的另一篇文章中找到了答案: https//stackoverflow.com/a/10359327/227349

<!--Next arg: forces node's stderror and stdout to a temporary file-->
<arg line=" &gt; _tempfile.out 2&lt;&amp;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 &amp; del _tempfile.out &amp; exit /b 1)"/>

<!--Next arg: Otherwise, just type the temporary file and delete it-->
<arg line=" &amp; type _tempfile.out &amp; del _tempfile.out &amp;"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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