如何从CI的NPM版本中获取错误代码(Windows)?(How do I get error codes (Windows) out of the NPM version of JSHint, fo

编程入门 行业动态 更新时间:2024-10-25 23:32:58
如何从CI的NPM版本中获取错误代码(Windows)?(How do I get error codes (Windows) out of the NPM version of JSHint, for CI?)

我们刚刚升级到Windows中的NPM版本的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失败,构建也会成功。

We've just upgraded to the NPM version of JSHint in Windows, and our CI won't fail on JSHint failures anymore. This feels like a silly problem, but I can't figure it out.

We're running NAnt and CCNet. When we try to run jshint.cmd from within NAnt, it fails saying that the path is wrong. 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").

So we've written a batch file which NAnt calls, which calls jshint.cmd. It now runs JSHint, but won't give error codes or fail properly. 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. I've tried checking resultproperty in NAnt as well with no luck.

Here's a few files:

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 output

[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.

最满意答案

我在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;"/>

I found the answer in another post on 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;"/>

更多推荐

本文发布于:2023-08-01 09:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1356753.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误代码   版本   CI   NPM   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!