Docker Jenkins slave wrong character encoding

2019-09-14 17:20发布

问题:

I'm using this Jenkins slave docker image, it is based on ubuntu:14.04

I would like to use a String Parameter which contains UTF-8 characters.

The charachers like öüóőúűáéí (Hungarian characters) will be replaced to question marks

As this ticket mentions I tried to pass -e LANG=hu_HU.UTF-8 and bash -c "locale-gen hu_HU.UTF-8" to docker. I also placed export LANG=hu_HU.UTF-8 to Jenkins user's .bashrc the characters are still replaced. I also tried with en_US.UTF-8

I also tried to do the same with the Jenkins Job:

+ export LANG=hu_HU.UTF-8
+ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=hu_HU.UTF-8
LANGUAGE=
LC_CTYPE="hu_HU.UTF-8"
LC_NUMERIC="hu_HU.UTF-8"
LC_TIME="hu_HU.UTF-8"
LC_COLLATE="hu_HU.UTF-8"
LC_MONETARY="hu_HU.UTF-8"
LC_MESSAGES="hu_HU.UTF-8"
LC_PAPER="hu_HU.UTF-8"
LC_NAME="hu_HU.UTF-8"
LC_ADDRESS="hu_HU.UTF-8"
LC_TELEPHONE="hu_HU.UTF-8"
LC_MEASUREMENT="hu_HU.UTF-8"
LC_IDENTIFICATION="hu_HU.UTF-8"
LC_ALL=    

The output is the same.

Thank you.

回答1:

An alternative (and perhaps cleaner) solution is to amend the Job configuration so that the environment variable is injected into the build job.

In the section Build Environment, add the environment variable in the 'Properties Content' field.

I think that this is a cleaner solution as the local jenkins account is not polluted leaving Jenkins installation to take care of the build environment; preferable when you have > 1 slave to maintain local accounts on... This solution is accurate as of Jenkins ver1.613



回答2:

I found the solution:

bash -c "locale-gen hu_HU && locale-gen hu_HU.UTF-8 && update-locale &&  echo 'export LANG=hu_HU.UTF-8' > /jenkins/.bashrc"