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