-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem capturing error output #117
Comments
I'm not sure what's going on here. Does it stop capturing on errors: The only thing I can think of is that when |
I've run the 2 command lines above on a project with jshint errors (adding the OK messages are output fine. |
Another note: using the |
I honestly have no idea what the problem might be. All the Does this happen for other tasks, or only for the |
Sorry for the delay: it seems to happen to every task. I just used |
If I could add my 2cents, this is probably the infamous node.js problem with stdout/stderr being cut off non deterministically on Windows when piped. AFAIK, this happens to everything that runs in Node on Windows. This works in cmd and powershell (output to the console): node.exe app.js The reason file redirection fails in powershell is that it's basically an alias for pipe into Out-File ... There is probably like a ton of bugs logged for various node apps that has this as underlying cause, e.g. this one in mocha: mochajs/mocha#333 |
I'm going to close this issue as it doesn't seem to be anything I can handle internally in grunt. If you think of something I can do, please let me know. |
@mcartoixa @cowboy Did anyone ever find a reasonable solution for this? Node 0.8.14 I have a Windows 2008 R2 server x86 (on EC2) as a Jenkins server. All of our builds are kicked off with Powershell. The bootstrap script verifies Node, NPM, PhantomJS and Bower installations, then installs packages with NPM, followed by Bower, and finally Grunt. This works great locally.. NPM, Bower and Grunt are all kicked off identically in the Powershell script. However, I'm only getting output from NPM and Bower in my output log on the build server. I've gone as far as launching Node by hand, and redirecting the output to an event stream (in .NET), and trying to push that to the output that Jenkins is capturing, but no love at all. I'm really stumped with the behavior I'm 'seeing. This is the hideous hack I've attempted under Jenkins. I get the word 'Initializing' from Grunt, and then that's it. # MAJOR HACK to redirect node.exe output on Jenkins
$process = New-Object Diagnostics.Process
$process.StartInfo.FileName = $localNode
$gruntCli = Join-Path (Get-CurrentDirectory) '..\node_modules\grunt-cli\bin\grunt'
$gruntFile = Join-Path (Get-CurrentDirectory) '..\Gruntfile.js'
$process.StartInfo.Arguments = @($gruntCli, $cmdLine, '--gruntfile', $gruntFile, '--verbose', '--no-color')
$process.StartInfo.UseShellExecute = $false
$process.StartInfo.RedirectStandardOutput = $true
$process.StartInfo.RedirectStandardError = $true
@{SourceIdentifier = 'GruntOutput'; EventName = 'OutputDataReceived'},
@{SourceIdentifier = 'GruntError'; EventName = 'ErrorDataReceived'} |
%{
Unregister-Event -SourceIdentifier $_.SourceIdentifier `
-ErrorAction SilentlyContinue
Register-ObjectEvent -InputObject $process @_
}
-
$process.Start() | Out-Null
$process.BeginOutputReadLine()
$process.BeginErrorReadLine()
function Get-EventMessages([string[]]$names)
{
$names |
% { Get-Event -SourceIdentifier $_ -ErrorAction SilentlyContinue } |
% {
if ($_.SourceEventArgs.Data)
{
Write-Host $_.SourceEventArgs.Data
}
Remove-Event -EventIdentifier $_.EventIdentifier
}
}
while (!$process.WaitForExit(100))
{
Get-EventMessages -names 'GruntOutput', 'GruntError'
}
Start-Sleep -Seconds 1
Get-EventMessages -names 'GruntOutput', 'GruntError'
$process.Close()
if ($process.ExitCode -ne 0) { throw 'Build aborted! Grunt failed.'} Note that the above does work fine on a local box as well... I'm just mystified here. I'm leaning towards this being some sort of edge case with Jenkins -> Powershell -> Node. I may try and pull Powershell out of the equation for the Grunt part, just to see what happens. |
It looks like people are having similar issues with Mocha. |
I should also note that I seem to be getting the node exitcode, which I read in Powershell and report as a failure. It's just that the output is going off into space. |
This is so wonky.. It seems that the issue is that Jenkins will only record the first console.log. I took Powershell out of the equation and mimicked the Grunt cli script. Then I told Jenkins to run the Node script var cwd = process.cwd()
//console.log('Working directory : ' + cwd);
//basically copied from node_modules/grunt_cli/bin/grunt script
// Nodejs libs.
var fs = require('fs');
var path = require('path');
// External libs.
var _dir = path.resolve(cwd, 'node_modules/grunt-cli/node_modules/lodash');
var _ = require(_dir);
var globdir = path.resolve(cwd, 'node_modules/grunt-cli/node_modules/glob');
var glob = require(globdir);
var gruntfile = path.resolve(cwd, 'Gruntfile.js');
var dir = path.resolve(gruntfile, '../node_modules/grunt');
// Run grunt.
var flushoutput = function()
{
while (process.stdout.bufferSize > 0) {
process.stdout.once('drain', exit);
}
while (process.stderr.bufferSize > 0) {
process.stderr.once('drain', exit);
}
}
require(dir).tasks('default', {"color": false, "verbose": true }, flushoutput); So when I run this, I only get the first line of Grunt
If I uncomment the So for whatever reason, the only output that gets captured is the very first thing sent to But there is clearly an issue here with Node and stdout. |
For anyone who might be following along, I also tried intercepting calls to process.stdout / process.stderr write ... and sending the strings to an array... so that I could make a single write call at the end. Couldn't get that working So to recap, failures
But I did finally find a solution if I drop down to cmd and execute this as part of my Jekins build steps.
Soooooooo... hacky, redirecting stdout / stderr to a file like that, but it amazingly works. I was starting to go nuts because I couldn't repro this locally -- only happening under Jenkins. Clearly less than ideal, but left as a work-around for posterity. |
Iristyle, just wanted to let you know I've used your approach and it solved the issues I was experiencing with the output being cut off. Thanks a bunch to explain what you have done to solve this issue! |
Update testing.md
I am currently trying to wrap the call to grunt in a custom MSBuild task so that it can integrate nicely in our (.NET based) continuous integration stack. Obviously, this is on WIndows.
The problem I have is that whenever there is an error in a grunt task (a jshint error for instance), my MSBuild task is not able to capture the errors for this task. Actually it seems I cannot have access to any output after (and including) the first error message.
I have been able to reproduce this behavior using a simple PowerShell command line:
powershell.exe -NonInteractive -NoLogo -ExecutionPolicy ByPass -Command "(node.exe grunt)"
works fine every time, whilepowershell.exe -NonInteractive -NoLogo -ExecutionPolicy ByPass -Command "Write-Host (node.exe grunt)"
eats every output after (and including) the first error (if any). The difference between these 2 command lines is that the first simply outputs the grunt output, while the second stores it in a temporary string then outputs it.I don't really understand what is happening here, but my wild guess is that the grunt process may under certain conditions, somehow, terminate before all its output is done...
Also, as a side note: shouldn't errors be output on the stderr stream instead of the sdtout one?
The text was updated successfully, but these errors were encountered: