Michael
Michael

Reputation: 146

Jenkins Console Print Encoded Characters

When outputting characters from a declarative pipeline running inside a linux container is it possible to change the encoding to match the true output from the terminal? I.e.

├── file1                         +-- file1
├── file2                         +-- file2
└── file3                         +-- file3

^Formatting I want                ^Formatting I get

.

I tried passing the following arguments to my Docker Agent:

-e JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF-8" 

-e LC_ALL="en_US.UTF-8"

.

Combined with:

sh returnStdout: true, script: " "

And got ├── in place of the "+--", which seems to be the ANSI encoding for the "├──".

I am using the ansiColor Option but that didn't seem to help much.

.

I saw this similar question, but I was unsure on how to implement the solution in the pipeline.

Jenkins: console output characters

Upvotes: 4

Views: 15943

Answers (3)

user3745418
user3745418

Reputation: 106

For me, the problem was really in specifying the optional 'encoding' parameter to the 'sh' pipeline step: sh: Shell Script

Of course, this will only work provided the file.encoding is set properly as described in other posts here.

Upvotes: 1

BB8
BB8

Reputation: 125

Here is the official answer from cloudbees. Unfortunately all of these did not work for me.

https://support.cloudbees.com/hc/en-us/articles/360004397911-How-to-address-issues-with-unmappable-characters-

Add these to JVM Arguments in master and also on agents -

-Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8

Upvotes: 6

Talha Junaid
Talha Junaid

Reputation: 2405

You can use Jenkins II to change the encoding to UTF-8. Go to Jenkins -> Manage Jenkins -> Configure System -> Global properties

and add two envirenment variables JAVA_TOOL_OPTIONS and LANG having values -Dfile.encoding=UTF-8 and en_US.UTF-8 respectively

. enter image description here

After adding these you may need to restart Jenkins.

Reference: https://www.linkedin.com/pulse/how-resolve-utf-8-encoding-issue-jenkins-ajuram-salim/

UPDATE:

or you can update <arguments> in jenkins.xml file. e.g.

<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -Dfile.encoding=UTF-8 -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"</arguments>

Upvotes: 9

Related Questions