question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ansicolor not rendering ansi color codes in Jenkins output.

See original GitHub issue

Test environment

- Jenkins Version: Jenkins 2.233
- AnsiColor Version: 0.6.3
- Operating System running Jenkins: amd64 Linux 4.14.173-106.229.amzn1.x86_64

Expected behavior

Jenkins pipeline calls Ansible to run a shell command with the shell module on a remote host. The shell runs an executable that returns ansi escape and color characters. Expected output is Ansicolor plugin rendering color codes in to defined colored text. image

Actual behavior

image image

When the Ansible module returns output that includes Ansi color code characters, Ansicolor-plugin is not rendering them as it should.

Steps to reproduce the behavior

Run ansible-playbook against a remote host ANSIBLE_FORCE_COLOR=true ANSIBLE_LOAD_CALLBACK_PLUGINS=1 ANSIBLE_STDOUT_CALLBACK=default ansible-playbook shell-script.yml The shell script should execute a command or program that produces text coloring in the output. e.g. printf, echo, … Ansible task output displayed in Jenkins will include output that contains unrenderred ansi color characters.

Issue checklist

  • Jenkins version
  • AnsiColor version
  • Operating System name and version
  • Expected behavior
  • Actual behavior
  • Steps to reproduce the behavior

First step is to upgrade to version 0.7.3 to see if that fixes our current issue.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
oliverericommented, Sep 24, 2020

I did just that. Debugged and stepped through what’s happening:

image

u'stdout corresponds to the raw output that is saved in a results dictionary. The string it points to below is what will get printed to the console. It looks like the AnsibleUnsafeText type when converted to a string makes sure to escape those sequences. We’re using the yaml callback plugin, when it uses yaml.dump() the escape sequence is itself escaped.

I’m Looking at how I might be able to allow those escapes to bubble up within Ansible so Ansicolor can do its work. Thanks for looking through this with us.

0reactions
tszmytkacommented, Sep 24, 2020

When Ansible sends the data back it may be escaping those escapes.

Exactly.

The following lines

^[[0;33m    printf '\u001b[31mhello world\u001b[0m'^[[0m
^[[0;33m  stdout: \u001b[31mhello world\u001b[0m^[[0m

confirm that this is indeed happening: ESC (shown as ^[) gets properly interpreted by ansicolor but \u001b from your yml gets escaped somewhere along the way and ends up being printed verbatim and thus - not interpreted.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ansi colors not seen while the console output is in progress
New issue originate from: #216 (comment) In freestyle job, AnsiColors are not seen while the console output is still in progress, ...
Read more >
AnsiColor | Jenkins plugin
This plugin adds support for standard ANSI escape sequences, including color, to Console Output. This plugin is available here and has a ...
Read more >
Colors are not displayed immediately after build using ...
After upgrading Jenkins AnsiColor plugin to version 0.6.0 or 0.6.1 or 0.6.2 colors are not immediately displayed in the Console log.
Read more >
Jenkins pipeline ansicolor console output - Stack Overflow
The AnsiColor Plugin "adds support for ANSI escape sequences, including color, to Console Output" ...
Read more >
Console output on jenkins is messed up and build failed is not ...
I installed the ANSIColor Plugin for Jenkins and it looks colorful now and does not have the ugly ANSI color codes.. David's profile...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found