How do I include console colors emitted from .NET applications (windows)

236 views
Skip to first unread message

Brent Scriver

unread,
Mar 2, 2015, 11:25:09 AM3/2/15
to jenkins...@googlegroups.com

I have the ansi color plugin installed and verified it works, however .NET or C++ applications setting console colors and emitting text does not appear colored in the log. Is there a configuration setting to enable it?

The .net code is pretty simple:
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.BackgroundColor = ConsoleColor.DarkCyan;
            Console.WriteLine("This should be dark red on a dark cyan background.");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.BackgroundColor = ConsoleColor.Cyan;
            Console.WriteLine("This should be red on a cyan background.");
        }

Producing the output:

I also tested a batch file with the text:

This resulted in the Jenkins output:

Recommendations?

Thank you for your time!

Brent






Baptiste Mathus

unread,
Mar 2, 2015, 12:15:28 PM3/2/15
to jenkins...@googlegroups.com

Try the ANSI color plugin? (Supposing .Net is emitting standard codes).

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/2b5baa64-ae89-494a-9e1e-869a0d566f07%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Slide

unread,
Mar 2, 2015, 12:20:24 PM3/2/15
to jenkins...@googlegroups.com
He mentioned in his email that he has the ANSI color plugin installed.

Baptiste Mathus

unread,
Mar 3, 2015, 3:55:16 AM3/3/15
to jenkins...@googlegroups.com
Right, read too quickly.

Just took the opportunity to try and crawl the now OSS'es .Net code: https://github.com/dotnet/corefx/tree/master/src/System.Console/src/System (disclaimer: I don't know DotNet at all)
Wild guess: seems like that ConsolePal class is wildly different for Windows & Unix. So I should think that code is not issuing ANSI codes? Or maybe there's a way to force output to be "Unix"?

Maybe some DotNet savvy guy could have a look and do a better job guessing what's wrong here? 

My 2 cents
HTH


For more options, visit https://groups.google.com/d/optout.

--
Baptiste <Batmat> MATHUS - http://batmat.net
Sauvez un arbre,
Mangez un castor !
nbsp;!

Brent Scriver

unread,
Mar 24, 2015, 12:10:01 PM3/24/15
to jenkins...@googlegroups.com, m...@batmat.net

I did some further digging as we had a C++ app behaving the same way: emitting color in a standard console but the color doesn't appear in Jenkins.

It turns out the C++ app (and presumably the C# one) is using the low level console APIs such as WriteConsole: https://msdn.microsoft.com/en-us/library/windows/desktop/ms687401%28v=vs.85%29.aspx. This isn't being captured by Jenkins. Not sure if there is a simple solution.

Brent

Ivo Bellin Salarin

unread,
Aug 6, 2015, 4:38:04 PM8/6/15
to jenkins...@googlegroups.com, m...@batmat.net

I suppose that the ANSI color plugin uses ANSI codes to detect colors.

I think that this is just unsupported on windows, since the windows console (cmd.exe -- invoked by Jenkins) is not a terminal emulator.

you could try using ansicon, according to stackoverflow. But this looks like a solution to set the colors using ansi codes, rather than a solution to emit ansi codes when the color is set.

Good luck, let us know if you find a solution!

Reply all
Reply to author
Forward
0 new messages