[Jenkins] Fixed java.nio.charset.UnmappableCharacterException: Input length = 1 on Windows

My Team upgrade Jenkins to Lasted LTS Version 2.361.1. After Upgrade and Test Jenkins on Windows. It shows error as follows

Started by upstream project "INVEST_WEBAPP_MAIN" build number 21
originally caused by:
 Started by user admin
Checking out git ${BASE_GIT_URL}/invest/invest-ui-winform.git into C:\Users\invest\.jenkins\workspace\INVEST_WEBAPP@script\9e3794ea3f16151ad721996b2010b40c01669b21510e34489e03b55d45e71363 to read jenkinsfile
The recommended git tool is: NONE
using credential git-jenkins
 > git.exe rev-parse --resolve-git-dir C:\Users\invest\.jenkins\workspace\INVEST_WEBAPP@script\9e3794ea3f16151ad721996b2010b40c01669b21510e34489e03b55d45e71363\.git # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url http://dev.local/invest/invest-ui-winform.git # timeout=10
Fetching upstream changes from http://dev.local/invest/invest-ui-winform.git
 > git.exe --version # timeout=10
 > git --version # 'git version 2.37.2.windows.2'
using GIT_ASKPASS to set credentials git-jenkins
 > git.exe fetch --tags --force --progress -- http://dev.local/invest/invest-ui-winform.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git.exe rev-parse "origin/release8.7.32^{commit}" # timeout=10
Checking out Revision f38fff5913c49aeeb7a7213aa01c9635a0a53c59 (origin/release8.7.32)
 > git.exe config core.sparsecheckout # timeout=10
 > git.exe checkout -f f38fff5913c49aeeb7a7213aa01c9635a0a53c59 # timeout=10
Commit message: "4bbfda85"
 > git.exe rev-list --no-walk b9a5c40749eb8fd8bff5c36417ab0b85aae280c6 # timeout=10
java.nio.charset.UnmappableCharacterException: Input length = 1
	at java.base/java.nio.charset.CoderResult.throwException(CoderResult.java:275)
	at java.base/java.lang.String.decodeWithDecoder(String.java:1205)
Caused: java.lang.Error
	at java.base/java.lang.String.decodeWithDecoder(String.java:1212)
	at java.base/java.lang.String.newStringNoRepl1(String.java:786)
	at java.base/java.lang.String.newStringNoRepl(String.java:738)
	at java.base/java.lang.System$2.newStringNoRepl(System.java:2390)
	at java.base/java.nio.file.Files.readString(Files.java:3369)
	at hudson.FilePath$ReadToString.invoke(FilePath.java:2377)
	at hudson.FilePath$ReadToString.invoke(FilePath.java:2372)
	at hudson.FilePath.act(FilePath.java:1192)
	at hudson.FilePath.act(FilePath.java:1175)
	at hudson.FilePath.readToString(FilePath.java:2369)
	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:188)
	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:70)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:311)
	at hudson.model.ResourceController.execute(ResourceController.java:107)
	at hudson.model.Executor.run(Executor.java:449)
Finished: FAILURE

Cause

import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.Map;

public class Test {

	public static void main(String[] args)
	{

		// Get the default charset of the machine
		Charset cs = Charset.defaultCharset();

		System.out.println("The default charset of the machine is :" + cs.displayName());
	}
}
  • The System tell me x-windows-874 .....
  • Change System Environment Variable Add
    • KEY: JAVA_TOOL_OPTIONS
    • VALUE: -Dfile.encoding=UTF8
  • Restart System & Run Test.java

Recap Solution

  1. add System Environment Variable
    • KEY JAVA_TOOL_OPTIONS
    • VALUE -Dfile.encoding=UTF8
  2. Restart System
  3. Test build

Because on It read jenkinsfile by using system default Encoding (Windows = x-windows-874)

Reference


Discover more from naiwaen@DebuggingSoft

Subscribe to get the latest posts sent to your email.