ansicolor-plugin icon indicating copy to clipboard operation
ansicolor-plugin copied to clipboard

partial logs not showing colors

Open AvihayTsayeg opened this issue 4 years ago • 42 comments

follow to #212

repreduces: free style job

#!/bin/bash
set -x
for i in {1..5000}; do  
echo -e $i '\033[0;37;42m[10]\033[0m \033[32m  my letters\033[0m'
done

image

image

image

AvihayTsayeg avatar Jan 11 '21 16:01 AvihayTsayeg

@AvihayTsayeg Thanks for the report and the example. I needed to beef it up a little (it had no ESC bytes).

The issue is fully reproducible. Plugin doesn't kick-in in a partial log output of a "Freestyle Project". Most of the time I use pipelines (where an equivalent script would work fine) so it slipped under my radar.

tszmytka avatar Jan 12 '21 21:01 tszmytka

Only now that I have a longer moment I see that the version I could reproduce this in was ansicolor-0.7.3 - the one still not having #214 .

After merging everything I am no longer able to reproduce the issue. I've just released ansicolor-0.7.4.

@AvihayTsayeg Could you please install the newest version and post the results?

tszmytka avatar Jan 16 '21 12:01 tszmytka

Many thanks 🙏 !!! I will install it soon, will let u know during the week. We have many builds and I want to check them all.

avihaycloudinary avatar Jan 16 '21 13:01 avihaycloudinary

@tszmytka Still there is an issue, We are using pipline, but for simplicity my examples are freeform. This image is after installing the new version. image

AvihayTsayeg avatar Jan 16 '21 17:01 AvihayTsayeg

Let's stick to comparing apples to apples.

  1. Can you please run the example you provided in the issue description?
  2. Could you also go to the update center's installed tab (your-jenkins-url/pluginManager/installed) and post a screenshot showing ansicolor plugin?

tszmytka avatar Jan 16 '21 22:01 tszmytka

finally could restart jenkins, image image image

AvihayTsayeg avatar Jan 19 '21 17:01 AvihayTsayeg

Please use example from the issue description - the one I updated with ESC bytes (\033). At best copy-paste it into a new "Freestyle project" job having only "Color ANSI Console Output" option checked.

If you have any of the following plugins installed, please provide their versions:

  • Timestamper
  • Kubernetes plugin

Are you running the job directly on the jenkins host or by means of agents? Maybe through docker and/or k8s?

tszmytka avatar Jan 19 '21 20:01 tszmytka

We do not use Kubernetes plugin,

image

the result for \033 are just fine. image

The main issue is some builds the log is fine and some not, I suspect the issue is the place which the log is getting cut for partial log.

AvihayTsayeg avatar Jan 19 '21 20:01 AvihayTsayeg

the result for \033 are just fine.

Ok, this means the script you've been using in issue description contains control characters that interfere with the whole processing. Here's how you posted it before my adjustment:

#!/bin/bash
set -x
for i in {1..5000}; do  
echo -e '[0;37;42m[10]�[0m �[32m  my letters'
done

The control characters probably have gotten garbled into � - which makes it impossible to reproduce (� doesn't trigger ANSI sequence processing so output remains as-is in both short and long console output).

Can you check what these characters are? Or better yet - can you put your original script into a file and attach it to the issue? Please make sure it is the one that produces output exactly as shown in issue description screenshot.

tszmytka avatar Jan 20 '21 10:01 tszmytka

I have create a gist see how it looks in editing note the red dots, after save the dots disappeared. image

link to gist https://gist.github.com/AvihayTsayeg/bba2eb6dc955bffbfc792b9e86c3bed5

AvihayTsayeg avatar Jan 20 '21 11:01 AvihayTsayeg

Luckily github leaves control characters in gists. Both of the invisible characters are ESC - this should all be working correctly and indeed is working on any jenkins I've tested it with (with ansicolor 0.7.4 obviously).

One thing that is different with my output and screenshots from issue description is that your run seems to produce more (by about 9KB) output. Is any other option enabled/set/filled in your job configuration apart from "Color ANSI Console Output" and "Command" textbox filled with the script? Also could you run the following script in your script console (your-jenkins-url/script) and post the results:

Jenkins.instance.pluginManager.plugins.each{
  plugin -> 
    println ("${plugin.getDisplayName()} (${plugin.getShortName()}): ${plugin.getVersion()}")
}

tszmytka avatar Jan 20 '21 19:01 tszmytka

@tszmytka Sent u mail with the complete plugins details

the diff size might be to set -x ?

AvihayTsayeg avatar Jan 20 '21 19:01 AvihayTsayeg

Confirmed with:

  • AnsiColor 0.7.4
  • Jenkins 2.263.2
  • Java 11
  • Amazon Linux 2

DavidPerezIngeniero avatar Jan 21 '21 11:01 DavidPerezIngeniero

I think the set -x is causing this issue in the example I sent. without it it is working fine on my Jenkins

without set -x image

AvihayTsayeg avatar Jan 21 '21 11:01 AvihayTsayeg

@AvihayTsayeg

Sent u mail with the complete plugins details

Thanks - got it. Feel free to remove your content if you don't want it to hang in the net.

I think the set -x is causing this issue in the example I sent.

This is a very interesting finding - thanks for that. I used set -x in all my successful runs so it can't be the only reason but I will try to play around with it - seems like a good lead.

tszmytka avatar Jan 21 '21 20:01 tszmytka

Any workaround? Maybe an older version of Jenkins or the Ansi plugin?

DavidPerezIngeniero avatar Feb 02 '21 10:02 DavidPerezIngeniero

I can confirm this. There is still an issue after #214. In the case I start viewing the log on the very beginning of the job everything works as expected. But when opening the console after the a while or even after the finished and when Jenkins displays the partial log output message, I see raw ansi escape sequences and no colors.

Upgrade 0.7.5 did not solve the problem. I'm using Jenkins 2.271.

The logs are coming out of a pipeline execution from a slave node which is running on the same machine. Neither timestamper nor kubernetes / docker plugins are installed.

roehrijn avatar Feb 14 '21 21:02 roehrijn

Please have a look into the proposed #220. I noted down some thoughts about the cause of the problem after some debugging sessions and proposed a fix, which I know, is not going to solve all aspects of the problem.

roehrijn avatar Mar 09 '21 21:03 roehrijn

Confirmed with:

AnsiColor: 0.7.5 Jenkins: 2.277.1 Java: 1.8.0b201 OS: CentOS 7.6

But AnsiColor 0.5.3 - works ok.

JiffsMaverick avatar Apr 05 '21 21:04 JiffsMaverick

Jenkins: 2.235.2 AnsiColor: 0.7.5

I confirm the problem, I have a log of about 130kb from the ansible, and part of the log is colored and part is not. I tried to put the version AnsiColor 0.5.3 - not work.

nuBacuk avatar Apr 21 '21 00:04 nuBacuk

I confirm that downgraded to version 0.5.3 and works flawlessly! :-)

DavidPerezIngeniero avatar Apr 21 '21 06:04 DavidPerezIngeniero

Hi @nuBacuk, could be you're hunting a different bug than me, @JiffsMaverick, @DavidPerezIngeniero for example. I think there is a difference between having no color at all in case the log is shown only partially in case it is too big and no color showing after a while in the log, but all the log is displayed.

0.5.3 also works for my usecase.

roehrijn avatar Apr 21 '21 12:04 roehrijn

To anyone experiencing this problem: Could you please post the actual job/pipeline that you are using and a screenshot of the output? I have not been able to reproduce this bug with the script posted in the initial description till this day.

tszmytka avatar Apr 21 '21 20:04 tszmytka

I did further analysis and now can say that the bug was introduced by b1336fd and a5d7d8c. Thus, ansicolor-0.6.3 is the last version without this bug.

b1336fd does not compile and a5d7d8c is fixing that together with a lot more other stuff. That's why I currently can't say which of both exactly introduced it.

I'm able to reproduce it on Linux with the Bash script above in a freestyle job with nothing more than the ansicolor checkbox ticked and the script added as a "script" build step.

I'm also able to reproduce it on Windows with similar setup but replacing the Bash script with this Windows Batch script:

@Echo off
Setlocal
::EchoANSI.cmd
cls
:: Display a sample of all the ANSI colours.
:: Requires windows 1909 or newer

:: Define foreground and background ANSI colors:
Set _fBlack=[30m
Set _bBlack=[40m
Set _fRed=[31m
Set _bRed=[41m
Set _fGreen=[32m
Set _bGreen=[42m
Set _fYellow=[33m
Set _bYellow=[43m
Set _fBlue=[34m
Set _bBlue=[44m
Set _fMag=[35m
Set _bMag=[45m
Set _fCyan=[36m
Set _bCyan=[46m
Set _fLGray=[37m
Set _bLGray=[47m
Set _fDGray=[90m
Set _bDGray=[100m
Set _fBRed=[91m
Set _bBRed=[101m
Set _fBGreen=[92m
Set _bBGreen=[102m
Set _fBYellow=[93m
Set _bBYellow=[103m
Set _fBBlue=[94m
Set _bBBlue=[104m
Set _fBMag=[95m
Set _bBMag=[105m
Set _fBCyan=[96m
Set _bBCyan=[106m
Set _fBWhite=[97m
Set _bBWhite=[107m
Set _RESET=[0m

for /l %%x in (1, 1, 1000) do (
Echo %_RESET% Black foreground 30
Echo %_fBlack%%_bRed% Black/Red  %_fBlack%%_bGreen%Black/Green %_fBlack%%_bYellow%Black/Yellow %_fBlack%%_bBlue% Black/Blue   %_fBlack%%_bMag%Black/Magenta %_fBlack%%_bCyan% Black/Cyan  %_fBlack%%_bLGray%Black/lGray
Echo %_fBlack%%_bDGray%Black/dGray %_fBlack%%_bBRed% Black/lRed %_fBlack%%_bBGreen%Black/lGreen %_fBlack%%_bBYellow%Black/lYellow %_fBlack%%_bBBlue% Black/lBlue  %_fBlack%%_bBMag%Black/lMagenta %_fBlack%%_bBCyan%Black/lCyan %_fBlack%%_bBWhite%Black/White
Echo %_RESET% Red foreground 31
Echo %_fRed%%_bBlack% Red/Black %_fRed%%_bGreen% Red/Green %_fRed%%_bYellow% Red/Yellow %_fRed%%_bBlue% Red/Blue %_fRed%%_bMag% Red/Magenta %_fRed%%_bCyan% Red/Cyan   %_fRed%%_bLGray% Red/lGray
Echo %_fRed%%_bDGray% Red/dGray %_fRed%%_bBRed% Red/lRed %_fRed%%_bBGreen% Red/lGreen %_fRed%%_bBYellow% Red/lYellow %_fRed%%_bBBlue% Red/lBlue %_fRed%%_bBMag% Red/lMagenta %_fRed%%_bBCyan% Red/lCyan %_fRed%%_bBWhite% Red/White
Echo %_RESET% Green foreground 32
Echo %_fGreen%%_bBlack%Green/Black %_fGreen%%_bRed% Green/red %_fGreen%%_bYellow%Green/Yellow  %_fGreen%%_bBlue% Green/Blue   %_fGreen%%_bMag%Green/Magenta %_fGreen%%_bCyan%Green/Cyan %_fGreen%%_bLGray%Green/lGray
Echo %_fGreen%%_bDGray%Green/dGray %_fGreen%%_bBRed%Green/lRed %_fGreen%%_bBGreen% Green/lGreen %_fGreen%%_bBYellow%Green/lYellow %_fGreen%%_bBBlue% Green/lBlue  %_fGreen%%_bBMag%Green/lMagenta %_fGreen%%_bBCyan%Green/lCyan %_fGreen%%_bBWhite%Green/White
Echo %_RESET% Yellow foreground 33
Echo %_fYellow%%_bBlack%Yellow/Black %_fYellow%%_bRed%Yellow/Red  %_fYellow%%_bGreen%Yellow/Green  %_fYellow%%_bBlue% Yellow/Blue   %_fYellow%%_bMag%Yellow/Magenta %_fYellow%%_bCyan%Yellow/Cyan %_fYellow%%_bLGray%Yellow/lGray
Echo %_fYellow%%_bDGray%Yellow/dGray %_fYellow%%_bBRed%Yellow/lRed %_fYellow%%_bBGreen%Yellow/lGreen %_fYellow%%_bBYellow%Yellow/lYellow %_fYellow%%_bBBlue% Yellow/lBlue  %_fYellow%%_bBMag%YellowlMagenta %_fYellow%%_bBCyan%Yellow/lCyan %_fYellow%%_bBWhite%Yellow/White
Echo %_RESET% Blue foreground 34
Echo %_fBlue%%_bBlack% Blue/Black %_fBlue%%_bRed% Blue/Red  %_fBlue%%_bGreen% Blue/Green %_fBlue%%_bYellow% Blue/Yellow   %_fBlue%%_bMag% Blue/Magenta %_fBlue%%_bCyan% Blue/Cyan %_fBlue%%_bLGray% Blue/lGray
Echo %_fBlue%%_bDGray% Blue/dGray %_fBlue%%_bBRed% Blue/lRed %_fBlue%%_bBGreen% Blue/lGreen %_fBlue%%_bBYellow% Blue/lYellow %_fBlue%%_bBBlue% Blue/lBlue   %_fBlue%%_bBMag% Blue/lMagenta %_fBlue%%_bBCyan% Blue/lCyan %_fBlue%%_bBWhite% Blue/White
Echo %_RESET% Magenta foreground 35
Echo %_fMag%%_bBlack%Magenta/Black %_fMag%%_bRed%Magenta/Red  %_fMag%%_bGreen% Magenta/Green %_fMag%%_bYellow%Magenta/Yellow  %_fMag%%_bBlue% Magenta/Blue %_fMag%%_bCyan% Magenta/Cyan %_fMag%%_bLGray%Magenta/lGray
Echo %_fMag%%_bDGray%Magenta/dGray %_fMag%%_bBRed%Magenta/lRed %_fMag%%_bBGreen%Magenta/lGreen %_fMag%%_bBYellow%Magenta/lYellow %_fMag%%_bBBlue%Magenta/lBlue %_fMag%%_bBMag%Magenta/lMagenta %_fMag%%_bBCyan%Magenta/lCyan %_fMag%%_bBWhite%Magenta/White
Echo %_RESET% Cyan foreground 36
Echo %_fCyan%%_bBlack% Cyan/Black  %_fCyan%%_bRed% Cyan/Red  %_fCyan%%_bGreen% Cyan/Green  %_fCyan%%_bYellow% Cyan/Yellow %_fCyan%%_bBlue% Cyan/Blue  %_fCyan%%_bMag% Cyan/Magenta  %_fCyan%%_bLGray% Cyan/lGray 
Echo %_fCyan%%_bDGray% Cyan/dGray  %_fCyan%%_bBRed%Cyan/lRed  %_fCyan%%_bBGreen%Cyan/lGreen  %_fCyan%%_bBYellow%Cyan/lYellow %_fCyan%%_bBBlue%Cyan/lBlue  %_fCyan%%_bBMag%Cyan/lMagenta  %_fCyan%%_bBCyan%Cyan/lCyan  %_fCyan%%_bBWhite%Cyan/White
Echo %_RESET% LightGray foreground 37 (lGray)
Echo %_fLGray%%_bBlack%lGray/Black %_fLGray%%_bRed%lGray/Red  %_fLGray%%_bGreen% lGray/Green %_fLGray%%_bYellow% lGray/Yellow %_fLGray%%_bBlue% lGray/Blue %_fLGray%%_bMag% lGray/Magenta %_fLGray%%_bCyan% lGray/Cyan
Echo %_fLGray%%_bDGray%lGray/dGray %_fLGray%%_bBRed%lGray/lRed %_fLGray%%_bBGreen%lGray/lGreen %_fLGray%%_bBYellow%lGray/lYellow %_fLGray%%_bBBlue%lGray/lBlue %_fLGray%%_bBMag%lGray/lMagenta %_fLGray%%_bBCyan%lGray/lCyan %_fLGray%%_bBWhite%lGray/White
Echo %_RESET% Dark Gray foreground 90 (dGray)
Echo %_fDGray%%_bBlack% dGray/Black %_fDGray%%_bRed% dGray/Red   %_fDGray%%_bGreen% dGray/Green  %_fDGray%%_bYellow%dGray/Yellow %_fDGray%%_bBlue% dGray/Blue    %_fDGray%%_bMag%dGray/Magenta %_fDGray%%_bCyan%dGray/Cyan %_fDGray%%_bLGray%dGray/lGray
Echo %_fDGray%%_bBRed%d Gray/lRed  %_fDGray%%_bBGreen%dGray/lGreen %_fDGray%%_bBYellow%dGray/lYellow %_fDGray%%_bBBlue% dGray/lBlue %_fDGray%%_bBMag%dGray/lMagenta %_fDGray%%_bBCyan% dGray/lCyan  %_fDGray%%_bBWhite%dGray/White
Echo %_RESET% Light Red foreground 91 (lRed)
Echo %_fBRed%%_bBlack% lRed/Black %_fBRed%%_bRed%  lRed/Red   %_fBRed%%_bGreen% lRed/Green   %_fBRed%%_bYellow% lRed/Yellow %_fBRed%%_bBlue% lRed/Blue %_fBRed%%_bMag% lRed/Magenta %_fBRed%%_bCyan% lRed/Cyan %_fBRed%%_bLGray% lRed/lGray
Echo %_fBRed%%_bDGray% lRed/dGray %_fBRed%%_bBGreen% lRed/lGreen %_fBRed%%_bBYellow% lRed/lYellow %_fBRed%%_bBBlue% lRed/lBlue  %_fBRed%%_bBMag% lRed/lMagenta %_fBRed%%_bBCyan% lRed/lCyan %_fBRed%%_bBWhite% lRed/White
Echo %_RESET% Light Green foreground 92 (lGreen)
Echo %_fBGreen%%_bBlack%lGreen/Black %_fBGreen%%_bRed% lGreen/Red %_fBGreen%%_bGreen% lGreen/Green  %_fBGreen%%_bYellow%lGreen/Yellow %_fBGreen%%_bBlue% lGreen/Blue  %_fBGreen%%_bMag%lGreen/Magenta %_fBGreen%%_bCyan%lGreen/Cyan %_fBGreen%%_bLGray%lGreen/lGray
Echo %_fBGreen%%_bDGray%lGreen/dGray %_fBGreen%%_bBRed%lGreen/lRed %_fBGreen%%_bBYellow%lGreen/lYellow %_fBGreen%%_bBBlue% lGreen/lBlue %_fBGreen%%_bBMag%lGreen/lMagenta %_fBGreen%%_bBCyan%lGreen/lCyan %_fBGreen%%_bBWhite%lGreen/White
Echo %_RESET% Light yellow foreground 93 (lYellow)
Echo %_fBYellow%%_bBlack%lYellow/Black %_fBYellow%%_bRed% lYellow/Red %_fBYellow%%_bGreen% lYellow/Green %_fBYellow%%_bYellow%lYellow/Yellow %_fBYellow%%_bBlue% lYellow/Blue   %_fBYellow%%_bMag%lYellow/Magenta %_fBYellow%%_bCyan%lYellow/Cyan %_fBYellow%%_bLGray%lYellow/lGray
Echo %_fBYellow%%_bDGray%lYellow/dGray %_fBYellow%%_bBRed%lYellow/lRed %_fBYellow%%_bBGreen%lYellow/lGreen %_fBYellow%%_bBBlue% lYellow/lBlue %_fBYellow%%_bBMag%lYellow/lMagenta %_fBYellow%%_bBCyan%lYellow/lCyan %_fBYellow%%_bBWhite%lYellow/White
Echo %_RESET% Light blue foreground 94 (lBlue)
Echo %_fBBlue%%_bBlack% lBlue/Black %_fBBlue%%_bRed% lBlue/Red  %_fBBlue%%_bGreen% lBlue/Green  %_fBBlue%%_bYellow% lBlue/Yellow  %_fBBlue%%_bBlue%  lBlue/Blue   %_fBBlue%%_bMag% lBlue/Magenta %_fBBlue%%_bCyan% lBlue/Cyan %_fBBlue%%_bLGray% lBlue/lGray
Echo %_fBBlue%%_bDGray% lBlue/dGray %_fBBlue%%_bBRed% lBlue/lRed %_fBBlue%%_bBGreen% lBlue/lGreen %_fBBlue%%_bBYellow% lBlue/lYellow %_fBBlue%%_bBMag% lBlue/lMagenta %_fBBlue%%_bBCyan% lBlue/lCyan %_fBBlue%%_bBWhite% lBlue/White
Echo %_RESET% Light Magenta foreground 95 (lMagenta)
Echo %_fBMag%%_bBlack%lMagenta/Black %_fBMag%%_bRed% lMagenta/Red %_fBMag%%_bGreen% lMagenta/Green %_fBMag%%_bYellow%lMagenta/Yello %_fBMag%%_bBlue%lMagenta/Blue %_fBMag%%_bMag%lMagenta/Magenta %_fBMag%%_bCyan%lMagenta/Cyan %_fBMag%%_bLGray%lMagenta/lGray
Echo %_fBMag%%_bDGray%lMagenta/dGray %_fBMag%%_bBRed%lMagenta/lRed %_fBMag%%_bBGreen%lMagenta/lGreen %_fBMag%%_bBYellow%lMagenta/lYellow %_fBMag%%_bBBlue%lMagenta/lBlue %_fBMag%%_bBCyan%lMagenta/lCyan %_fBMag%%_bBWhite%lMagenta/White
Echo %_RESET% Light Cyan foreground 96 (lCyan)
Echo %_fBCyan%%_bBlack% lCyan/Black %_fBCyan%%_bRed% lCyan/Red  %_fBCyan%%_bGreen% lCyan/Green  %_fBCyan%%_bYellow% lCyan/Yellow  %_fBCyan%%_bBlue% lCyan/Blue  %_fBCyan%%_bMag% lCyan/Magenta  %_fBCyan%%_bCyan% lCyan/Cyan %_fBCyan%%_bLGray% lCyan/lGray
Echo %_fBCyan%%_bDGray% lCyan/dGray %_fBCyan%%_bBRed% lCyan/lRed %_fBCyan%%_bBGreen% lCyan/lGreen %_fBCyan%%_bBYellow% lCyan/lYellow %_fBCyan%%_bBBlue% lCyan/lBlue %_fBCyan%%_bBMag% lCyan/lMagenta %_fBCyan%%_bBWhite% lCyan/White
Echo %_RESET% White foreground 97
Echo %_fBWhite%%_bBlack% White/Black %_fBWhite%%_bRed% White/Red  %_fBWhite%%_bGreen% White/Green %_fBWhite%%_bYellow% White/Yellow   %_fBWhite%%_bBlue% White/Blue  %_fBWhite%%_bMag% White/Magenta  %_fBWhite%%_bCyan% White/Cyan %_fBWhite%%_bLGray% White/lGray
Echo %_fBWhite%%_bDGray% White/dGray %_fBWhite%%_bBRed% White/lRed %_fBWhite%%_bBGreen% White/lGreen %_fBWhite%%_bBYellow% White/lYellow %_fBWhite%%_bBBlue% White/lBlue %_fBWhite%%_bBMag% White/lMagenta %_fBWhite%%_bBCyan% White/lCyan

)

:: reset
Echo %_RESET%

:: SS64.com

This script is from https://ss64.com/nt/echoansi.txt and slightly modified to run in a loop.

roehrijn avatar Apr 22 '21 07:04 roehrijn

and @tszmytka, this is the screenshot of the output: image

roehrijn avatar Apr 22 '21 07:04 roehrijn

Again new findings:

Until 0.6.x I can reproduce the bug with exactly the setup in this repository. Just by checking out and running mvn hpi:run. Starting with 0.7 I can't reproduce it in all cases, but I can reproduce it when I show the log of a currently running build which is already that far that the console log is showing only partly. In this case it is shown without colors. When reloading the console after the build has finished, color are shown.

The issue is located in ColorizedAction.java:

    public static ColorizedAction parseAction(String lineContent, long lineNo, Run<?, ?> run, LineIdentifier lineIdentifier) {
        return run.getActions(ColorizedAction.class).stream().filter(a -> lineIdentifier.isEqual(lineContent, lineNo, a.id)).findAny().orElse(CONTINUE);
    }

In case the build is finished, run.getActions(ColorizedAction.class) retrieves two ColorizedActions, one with a UUID as id (the one which could also be found in the build.xml of the build) and one containing the hash of the first displayed line as id. This prevents that function from returning the CONTINUE-Action. In case the build is not yet finished but far enough to only show a partial log, run.getActions(ColorizedAction.class) retrieves only the action with the UUID. Which leads to the CONTINUE-Action to be returned.

roehrijn avatar Apr 22 '21 12:04 roehrijn

@roehrijn Nice idea with the windows batch script, didn't even expect the os to be capable of rendering ANSI escape codes. Can you write which ansicolor and Jenkins versions you were using while getting the screenshot?

I ran it on my end with ansicolor-0.7.5 in Jenkins 2.204.6, 2.260, and 2.271 and it renders output with colors just fine. Another thing, just to be 100% sure we are talking about the same problem: Clicking on Full Log shows colors correctly right? It is only the tailed output that doesn't do that, correct?

Re.

but I can reproduce it when I show the log of a currently running build which is already that far that the console log is showing only partly. In this case it is shown without colors.

I haven't tested such a case but thinking about this now I can confirm that tailed output won't be colored while the build is running. Current implementation simply doesn't have this covered. Either way this is a separate issue - let's focus here on what happens after build has finished.

tszmytka avatar Apr 22 '21 21:04 tszmytka

I have the same issue but i have found why we have the issue.

Jenkins: 2.263.4 AnsiColor: 0.7.5

To confirm our issue, while the job is running, the output is correct all the way up to completion. When we refresh the page or revisit it, the problem occurs. I have found a fixed (in our use case) and can replicate:

This pipeline job works fine including after refresh:

ansiColor('xterm') {
    node {
        stage('test') { // for display purposes
            sh 'printf "\\e[31mHello World\\e[0m\\n"'
            sh 'printf "Normal \\e[1mBold\\e[0m\\n"'
            sh 'printf "Normal \\e[4mUnderlined\\e[0m\\n"'
        }
    }
}

image But we use the logstash plugin to output the logs to ES so the actual setup we use is this:

logstash {
    ansiColor('xterm') {
        node {
            stage('test') { // for display purposes
                sh 'printf "\\e[31mHello World\\e[0m\\n"'
                sh 'printf "Normal \\e[1mBold\\e[0m\\n"'
                sh 'printf "Normal \\e[4mUnderlined\\e[0m\\n"'
                
                sleep 5
            }
        }
    }
}

The output is fine during the run (had to put a sleep in to see the job showed correctly during the run) but after refreshing i get the issue: image If i switch around the logstash and ansi classes it works fine:

ansiColor('xterm') {
    logstash {
        node {
            stage('test') { // for display purposes
                sh 'printf "\\e[31mHello World\\e[0m\\n"'
                sh 'printf "Normal \\e[1mBold\\e[0m\\n"'
                sh 'printf "Normal \\e[4mUnderlined\\e[0m\\n"'
                
                sleep 5
            }
        }
    }
}

thenom avatar Apr 27 '21 15:04 thenom

The issue is reproduced on version 0.7.5 on Jenkins 2.277.2, with freestyle job. It only occurs while the console output is still in progress, so it shows for example: [33mThis should be yellow text[0m

Notes:

  1. If going to /consoleFull page - Then Ansi colors are shown correctly.
  2. Once the build completes, refreshing the /console page also shows Ansi colors correctly.

manosnoam avatar May 16 '21 08:05 manosnoam

@manosnoam Your problem seems to be a separate thing. This issue is about log output not getting interpreted by ansicolor after build completes. As you wrote - yours looks fine. Please open a new issue with example pipeline where this is observable.

tszmytka avatar May 16 '21 20:05 tszmytka