4

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

Michael
  • 145
  • 1
  • 1
  • 5

3 Answers3

9

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>
Talha Junaid
  • 2,351
  • 20
  • 29
  • Unfortunately I tried this and it didn't work. I was able fix my issue by deleting my local jenkins and running java -Dfile.encoding=UTF-8 -jar jenkins.war, but that option isn't feasible for our production jenkins. Do you know of a jenkins startup folder that runs java commands? – Michael Aug 23 '18 at 22:54
  • 1
    OOH, you totally led my to the answer that worked for me. I added "-Dfile.encoding=UTF-8" to the jenkins config file (jenkins.xml) Thanks! – Michael Aug 23 '18 at 23:01
6

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
BB8
  • 125
  • 1
  • 8
  • 1
    only this helped in my case. – chandu May 10 '21 at 21:07
  • This was the only solution that worked for me as well. To clarify, the changes needed to be made in the Jenkins.xml file on the master, and the jenkins-slave.xml file on the agents and in the arguments section for both. – Jand Jul 19 '21 at 23:21
0

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.