gpt4 book ai didi

node.js - Teamcity 运行的 Grunt 无法正确输出到日志

转载 作者:太空宇宙 更新时间:2023-11-03 23:41:01 24 4
gpt4 key购买 nike

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

当我执行 grunt default 时,输出(在 Teamcity 日志中)不包含 grunt 的相关错误输出。然而,它确实返回适当的非零退出代码,这会导致 teamcity 构建正确失败。但我没有收到 grunt 错误日志。

本页:https://www.npmjs.org/package/grunt-teamcity描述了针对我遇到的问题的以下解决方法:

Teamcity on windows does not flush the stdout stream before exiting the grunt node process. There has been some work around this in both nodejs and grunt, but it is by no means resolved. If you see missing output in your Teamcity build log then try running the grunt task using the TC command line runner by redirecting output to a file, e.g:

grunt default --no-color > grunt.tmp & type grunt.tmp & del grunt.tmp Seems that by redirecting to a file the output is synchronous, whereas with pipe (or TC plugin execute method) the output is async and not captured before the node process exits.

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

我想这可以通过一些创造性的批处理脚本来解决,但我不知道如何解决这个问题。

最佳答案

@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%

关于node.js - Teamcity 运行的 Grunt 无法正确输出到日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23841999/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com