由Teamcity运行的Grunt不能正确输出到日志

我有一个teamcity构build运行grunt作为命令行任务。

当我执行grunt default的输出(在TeamCity日志中)不包含从grunt相关的错误输出。 但是,它会返回适当的非零退出代码,导致teamcity生成失败。 虽然我没有得到咕噜的错误日志。

此页面: https : //www.npmjs.org/package/grunt-teamcity描述了我面临的问题的以下解决方法:

windows上的Teamcity在退出grunt节点进程之前不刷新stdoutstream。 在nodejs和grunt中都有一些解决这个问题的方法,但是并没有解决。 如果您在Teamcity构build日志中看到缺less输出,请尝试使用TC命令行运行器将输出redirect到文件来运行grunt任务,例如:

grunt.tmp&type grunt.tmp&del grunt.tmp看来,通过redirect到一个文件的输出是同步的,而与pipe道(或TC插件执行方法)输出是asynchronous的,而不是捕获在节点进程退出之前。

所以它基本上build议你像这样运行grunt: grunt default --no-color > grunt.tmp & type grunt.tmp & del grunt.tmp 。 然而,这种方法的问题是始终返回0(零)作为退出代码,这意味着我的TeamCity构build不正常失败。

我想这可以解决一些有创意的批处理脚本,但我不知道如何处理这个。

 @echo off :: prepare environment setlocal enableextensions set "tempFile=%temp%\%~nx0.%random%.grunt.tmp" :: run grunt call grunt default --no-color > "%tempFile%" :: Keep the grunt exit code set "exitCode=%ERRORLEVEL%" :: Print the grunt output type "%tempFile%" :: cleanup and exit with adecuated value del /q "%tempFile%" >nul 2>nul endlocal & exit /b %exitCode% 
 call grunt default --no-color > temp.txt type temp.txt