문제 현상
CI/CD 구축 중 Jenkins Pipeline에서 JSON 파일을 작성하여 CentOS 호스트에 배포합니다.
Jenkins 서버는 Windows 위에서 동작하고 있으며, 호스트는 배포된 JSON 파일을 환경 설정으로 하여 서버 애플리케이션을 실행합니다.
- 배포된 JSON 파일을 CentOS 호스트의 서버 애플리케이션이 읽어오지 못하고 있습니다.
- 동일한 텍스트를 CentOS 호스트에서 직접 파일 생성하면 정상적으로 처리됩니다.
- CentOS 호스트 위에서 동작하는 서버 애플리케이션은 실행과 동시에 인자로 JSON 파일을 로드합니다.
2022-07-15 05:32:52 [20819]Exception in thread "main" java.util.NoSuchElementException
2022-07-15 05:32:52 [20819]#011at java.base/java.util.Scanner.throwFor(Scanner.java:937)
2022-07-15 05:32:52 [20819]#011at java.base/java.util.Scanner.next(Scanner.java:1478)
2022-07-15 05:32:52 [20819]#011at io.vertx.core.impl.launcher.commands.BareCommand.getJsonFromFileOrString(BareCommand.java:289)
2022-07-15 05:32:52 [20819]#011at io.vertx.core.impl.launcher.commands.RunCommand.getConfiguration(RunCommand.java:420)
2022-07-15 05:32:52 [20819]#011at io.vertx.core.impl.launcher.commands.RunCommand.run(RunCommand.java:243)
2022-07-15 05:32:52 [20819]#011at io.vertx.core.impl.launcher.VertxCommandLauncher.execute(VertxCommandLauncher.java:226)
2022-07-15 05:32:52 [20819]#011at io.vertx.core.impl.launcher.VertxCommandLauncher.dispatch(VertxCommandLauncher.java:380)
2022-07-15 05:32:52 [20819]#011at io.vertx.core.impl.launcher.VertxCommandLauncher.dispatch(VertxCommandLauncher.java:324)
2022-07-15 05:32:52 [20819]#011at io.vertx.core.Launcher.main(Launcher.java:45)
문제 해결
JSON 파일이 작성된 OS에 따라서 처리 결과가 달라지고 있습니다.
텍스트 파일의 인코딩 타입을 가장 먼저 의심할 수 있으며, 다음 명령문으로 파일 정보를 확인합니다.
$ file -bi [파일 이름]
Windows에서 실행된 Jenkins Pipeline이 작성한 JSON 파일 정보입니다.
text/plain; charset=iso-8859-1
CentOS에서 직접 작성한 JSON 파일 정보입니다.
text/plain; charset=utf-8
두 파일의 인코딩 타입이 서로 다릅니다.
파일이 작성될 때 인코딩 타입을 서로 일치시켜주면 해결될 것으로 보입니다.
- Jenkins Pipeline에서 writeFile()에 encoding 타입을 명시합니다.
stage('Write JSON file stage') {
steps {
writeFile(
file:'test.json',
text:"${params.server_app_conf}",
encoding:"UTF-8"
)
}
}
다시 빌드하면 JSON 파일의 인코딩 타입이 명시된 것으로 정상 적용됩니다.
서버 애플리케이션 역시 JSON 파일을 정상 로드합니다.
text/plain; charset=utf-8
'Build > Jenkins' 카테고리의 다른 글
[Infrastructure/Jenkins] SSH Pipeline Steps 플러그인을 사용한 원격 호스트 제어 (0) | 2022.04.12 |
---|---|
[Infrastructure/Jenkins] 플러그인(Plugin) 설치 (0) | 2022.04.12 |
[Infrastructure/Jenkins] Scripted 파이프라인 기본 구문 (0) | 2022.04.12 |
[Infrastructure/Jenkins] 파이프라인 소개 및 젠킨스 웹 UI로 파이프라인 만들기 (0) | 2022.04.11 |
[Infrastructure/Jenkins] MacOS에서 도커(Docker)를 사용한 젠킨스 설치 (0) | 2022.04.06 |