jenkinsci / ansicolor-plugin

Jenkins ANSI Color Plugin
https://plugins.jenkins.io/ansicolor/
MIT License
252 stars 82 forks source link

partial logs not showing colors #216

Open AvihayTsayeg opened 3 years ago

AvihayTsayeg commented 3 years ago

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

tszmytka commented 3 years ago

@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 commented 3 years ago

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?

avihaycloudinary commented 3 years ago

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.

AvihayTsayeg commented 3 years ago

@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

tszmytka commented 3 years ago

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?
AvihayTsayeg commented 3 years ago

finally could restart jenkins, image image image

tszmytka commented 3 years ago

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:

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

AvihayTsayeg commented 3 years ago

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.

tszmytka commented 3 years ago

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.

AvihayTsayeg commented 3 years ago

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

tszmytka commented 3 years ago

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()}")
}
AvihayTsayeg commented 3 years ago

@tszmytka Sent u mail with the complete plugins details

the diff size might be to set -x ?

DavidPerezIngeniero commented 3 years ago

Confirmed with:

AvihayTsayeg commented 3 years ago

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

tszmytka commented 3 years ago

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

DavidPerezIngeniero commented 3 years ago

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

roehrijn commented 3 years ago

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 commented 3 years ago

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.

JiffsMaverick commented 3 years ago

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.

nuBacuk commented 3 years ago

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.

DavidPerezIngeniero commented 3 years ago

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

roehrijn commented 3 years ago

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.

tszmytka commented 3 years ago

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.

roehrijn commented 3 years ago

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=
Set _bBlack=
Set _fRed=
Set _bRed=
Set _fGreen=
Set _bGreen=
Set _fYellow=
Set _bYellow=
Set _fBlue=
Set _bBlue=
Set _fMag=
Set _bMag=
Set _fCyan=
Set _bCyan=
Set _fLGray=
Set _bLGray=
Set _fDGray=
Set _bDGray=
Set _fBRed=
Set _bBRed=
Set _fBGreen=
Set _bBGreen=
Set _fBYellow=
Set _bBYellow=
Set _fBBlue=
Set _bBBlue=
Set _fBMag=
Set _bBMag=
Set _fBCyan=
Set _bBCyan=
Set _fBWhite=
Set _bBWhite=
Set _RESET=

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 commented 3 years ago

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

roehrijn commented 3 years ago

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.

tszmytka commented 3 years ago

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

thenom commented 3 years ago

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
            }
        }
    }
}
manosnoam commented 3 years ago

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

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.

tszmytka commented 3 years ago

@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 commented 3 years ago

This is a shot in the dark but ansicolor-1.0.0 has just been released. It includes fixes for a couple of bugs that might have contributed to this issue as well. I would encourage everyone to try it out and report back the results.

madmanidze commented 3 years ago

Issue not fixed, same look on partial logs.

martincermak commented 3 years ago

Still the same - unformated partial output

Upgraded from ansicolor 0.7.4. Last known working version to us was ansicolor 0.4.2. Doesn't matter if the job is running or finished.

gjed commented 3 years ago

Same here: full log is formatted correctly, pipeline stage logs are not. Full: Screenshot from 2021-10-11 11-06-09

Pipeline stage logs (opened from stage view): Screenshot from 2021-10-11 11-05-48

Pipeline:

pipeline {
  agent any

  triggers {
    pollSCM('')
  }

  options{
      buildDiscarder(logRotator(numToKeepStr: '30'))
      timeout(time: 15, unit: 'MINUTES')
      disableConcurrentBuilds()
      ansiColor('xterm')
  }

  environment{
    agentImage = "sdk"
    agentTag = "21.40.0"
    cmd = "/app/cmd/dojo.sh 1>&2"

    repo = "leantime-boards"
    url = "https://<*redacted*>"
    tag = "latest"

    jenkinsCred = credentials('jenkins')
    dockerCred = credentials('docker')
    registry = "<*redacted*>"

    recipients = "jenkins" // alert" // toMod
  }

  stages {
    stage('Checkout') {
      steps {
        checkout([$class: "MercurialSCM", clean: true, source: "${url}", credentialsId: "jenkins", subdir:"<*redacted*>/${repo}"])
        echo sh(script: 'docker login -u $dockerCred_USR -p $dockerCred_PSW ${registry}', returnStdout: true).trim()
        echo sh(script: "docker image pull ${registry}/${agentImage}:${agentTag}", returnStdout: true).trim()
      }
    }
    stage('<*redacted*> - Build sources') {
      steps{
        echo sh(script: """
          docker container run \
          --name ${agentImage}-<*redacted*>-${BUILD_NUMBER} \
          --rm \
          -u oi \
          -v /app/jenkins/workspace/${JOB_NAME}/<*redacted*>:/app/repository/ \
          -e CLIENT=<*redacted*> \
          -e REPO=${repo} \
          ${registry}/${agentImage}:${agentTag} ${cmd}""", 
          returnStdout: true).trim()
      }
    }
    stage('<*redacted*> - Build docker image') {
      environment {
        image = "<*redacted*>"
      }
      steps{
        dir("${WORKSPACE}/<*redacted*>/${repo}") {
          script {
            env.maintainer = sh(script: 'hg --config auth.x.prefix=* --config auth.x.username=$jenkinsCred_USR --config auth.x.password=$jenkinsCred_PSW id --template \'{user}\'', returnStdout: true).trim()
            env.id = sh(script: 'hg --config auth.x.prefix=* --config auth.x.username=$jenkinsCred_USR --config auth.x.password=$jenkinsCred_PSW id', returnStdout: true).trim()
            env.version = sh(script: 'hg --config auth.x.prefix=* --config auth.x.username=$jenkinsCred_USR --config auth.x.password=$jenkinsCred_PSW id --template \'hg:{p1rev}, {branch}\'', returnStdout: true).trim()
          } 
          echo sh(script: """ docker image build \
            --pull \
            --rm \
            --no-cache \
            --build-arg hguser=\"\${maintainer}\" \
            --build-arg hgversion=\"(\${version}) (\${id})\" \
            ${WORKSPACE}/<*redacted*>/${repo} -t ${registry}/${env.image}:${tag}""", returnStdout: true).trim()
          echo sh(script: "docker image push ${registry}/${env.image}:${tag}", returnStdout: true).trim()
        }
      }
    }
  }

  post {
    unsuccessful{
      step([$class: 'Mailer', recipients:"${recipients}", notifyEveryUnstableBuild: true, sendToIndividuals: true])
    }
  }
}

NB: jenkins container has docker-cli installed and talks directly to the host docker deamon using docker context. Script output is formatted with bash printf. It use tput for colors etc.

# This is an example, a bit of cut n paste
export _bash_prefix=[$(tput setaf 6)$(tput bold)DOJO$(tput sgr0)] 

declare _bold="$(tput bold)"
declare _nrm="$(tput sgr0)"

declare _cyan="$(tput setaf 6)"
declare _bcyan="$_bold$_cyan"

_hello () {
  wc="$1"
  string="$2"
  printf "%s %s\n" "${_bash_prefix}" ""
  printf "%s %s\n" "${_bash_prefix}" "${_bold}------------------------------------------------------------------------"
  printf "\n"
  printf "%s\n" "${_bcyan}$(figlet -w $1 -c  $2 )${_nrm}"
  printf "\n"
  printf "%s %s\n" "${_bash_prefix}" "${_bold}------------------------------------------------------------------------"
  printf "%s %s\n" "${_bash_prefix}" ""
}

Env:

orzechszek commented 2 years ago

Issue stil exists on:

orzechszek commented 2 years ago

Any updates?

dblock commented 2 years ago

@orzechszek nope

kugel- commented 2 years ago

Still happening on Jenkins 2.336 and ansiColor 1.0.1

Following the console log is nearly impossible. I often see black text on black background which is only fixed once the job completes.

sha-root commented 2 years ago

Still happening on [Jenkins 2.346.3] and ansiColor 1.0.2 (it shows correctly during the build, and again problem when build is finished)

jenkins stage log view ansi color issue
shinebayar-g commented 2 years ago

This is a really nice plugin. Unfortunately run into this bug. Reproduced with instructions on the README.

Jenkins: 2.346.3 Latest LTS as of this moment AnsiColor: 1.0.2

pipeline {
    agent any
    options {
        timestamps()
        ansiColor('xterm')
    }
    stages {
        stage('Build') {
            steps {
                echo '\033[34mHello\033[0m \033[33mcolorful\033[0m \033[35mworld!\033[0m'
            }
        }
        stage('Test') {
            steps {
                echo 'hello from test step'
            }
        }
        stage('Deploy') {
            steps {
                echo 'hello from deploy step'
            }
        }
    }
}
  1. Stage logs don't render Ansi Colors

    ansicolor-1
  2. Console Output menu renders Ansi Colors correctly, only in full log mode or output is not trimmed. Doesn't render correctly if console output is trimmed. Screenshot not included for buggy case as my example output wasn't trimmed.

    ansicolor-2
  3. Build -> Pipeline steps -> Console Output doesn't render correctly (probably same as number 1). This was really unfortunate, individual step logs are much more useful than whole Console Output.

    ansicolor-3
hydrapolic commented 1 year ago

Pretty please, would help greatly :) Thanks!

fernando-renzi commented 1 year ago

To fix it, you need to go to Settings ---> Ansicolor ---> Global color map for all builds ---> and set it to xterm.