2022. 11. 24. 13:09ㆍInfra/CI-CD
Jenkins를 설치하고 아래와 같은 구성으로 세팅을 잡았습니다. webhook 방식이 아니라 Jenkins에서 '지금 빌드하기'를 눌렀을 때 GitHub의 소스를 가져와서 빌드를 진행하고 배포하는 구성입니다.
Docker로 2개의 컨테이너를 띄웠습니다. 하나는 Jenkins가 구동되는 컨테이너이며, 다른 하나는 Spring Application이 배포 될 컨테이너이며 우분투를 설치하였습니다. 이런 구성을 선택한 이유는 2가지 입니다. 하나는 사이드 프로젝트라 규모가 작기 때문이고, 또 다른 하나는 이전에 해보았던 방식들과는 조금 다른 방식으로 사용하기 위함입니다.
해당 구성방식은 링크를 남기고 에러에 대한 이야기로 넘어가겠습니다.
에러내용은 아래와 같습니다.
... 중략 ... ( git pull 로그 )
[Gradle] - Launching build.
[jenkins-spring] $ /var/jenkins_home/workspace/jenkins-spring/gradlew clean build
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain
Build step 'Invoke Gradle script' changed build result to FAILURE
Build step 'Invoke Gradle script' marked build as failure
Finished: FAILURE
정상적으로 프로젝트를 내려 받았고, Gradle로 Build를 시작하려고하는데, 위와 같은 에러가 발생했습니다. 내용을 읽어보면 Gradled을 찾을 수 없다는 내용입니다. 젠킨스 프로젝트 구성에서 공식 도큐먼트에 따라서 'Use Gradle Wrapper'를 사용해서 빌드를 진행했습니다. Wrapper는 선언 된 버전의 Gradle을 호출하여 필요한 경우 미리 다운로드하는 스크립트입니다. 결과적으로 수동 설치 프로세스를 수행하지 않고도 Gradle 프로젝트를 신속하게 시작할 수 있다는 장점이 있습니다.
위 에러가 발생했을 때 Gradle Wrapper를 Jenkins 컨테이너에 접속해서 확인을 해보았습니다. 문제는 Gradle Wrapper가 없었습니다.
개발환경에서 다시 체크를 해보니, Wrapper가 있었는데, Jenkins에는 없었습니다. 그래서 GitHub을 확인했는데, 거기는 없었습니다.
즉 , gitignore에 의해서 git에 push가 되지 않았던 부분이었습니다. ignore 파일에서 관련 내용을 주석 처리후 다시 git push를 진행했고 다시 빌드를 하였습니다.
근데 또 안됩니다. 이번에는 Jenkins 컨테이너에서 확인을 해보니 'gradel-wrapper.jar'만 없습니다. 이것만 왜 없는지 도통 이해가 되지않습니다. 해당 내용은 아직 확인중입니다.
결과적으로 가장 심플한 방법을 사용합니다. Jenkins에 gradle을 설치하고 빌드 환경설정을 아래와 같이 잡아줍니다.
[Gradle] - Launching build.
Unpacking https://services.gradle.org/distributions/gradle-7.6-rc-4-bin.zip to /var/jenkins_home/tools/hudson.plugins.gradle.GradleInstallation/gradle on Jenkins
[jenkins-spring] $ /var/jenkins_home/tools/hudson.plugins.gradle.GradleInstallation/gradle/bin/gradle clean build --stacktrace
Welcome to Gradle 7.6-rc-4!
Here are the highlights of this release:
- Added support for Java 19.
- Introduced `--rerun` flag for individual task rerun.
- Improved dependency block for test suites to be strongly typed.
- Added a pluggable system for Java toolchains provisioning.
For more details see https://docs.gradle.org/7.6-rc-4/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :clean UP-TO-DATE
> Task :compileJava
Note: /var/jenkins_home/workspace/jenkins-spring/src/main/java/com/pointreserve/reserves/common/domain/CustomIdGenerator.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
> Task :processResources
> Task :classes
> Task :jar
> Task :compileTestJava
> Task :processTestResources NO-SOURCE
> Task :testClasses
> Task :test
2022-11-23 08:10:21.972 INFO 2044 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-11-23 08:10:22.122 INFO 2044 --- [ionShutdownHook] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
Hibernate: drop table if exists account CASCADE
Hibernate: drop table if exists event_detail CASCADE
Hibernate: drop table if exists event_reserves CASCADE
Hibernate: drop sequence if exists hibernate_sequence
2022-11-23 08:10:24.342 INFO 2044 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2022-11-23 08:10:24.409 INFO 2044 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2022-11-23 08:10:24.915 INFO 2044 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-11-23 08:10:24.933 INFO 2044 --- [ionShutdownHook] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
Hibernate: drop table if exists account CASCADE
Hibernate: drop table if exists event_detail CASCADE
Hibernate: drop table if exists event_reserves CASCADE
Hibernate: drop sequence if exists hibernate_sequence
2022-11-23 08:10:25.872 INFO 2044 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-2 - Shutdown initiated...
2022-11-23 08:10:25.944 INFO 2044 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-2 - Shutdown completed.
2022-11-23 08:10:25.972 INFO 2044 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-11-23 08:10:25.993 INFO 2044 --- [ionShutdownHook] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
Hibernate: drop table if exists account CASCADE
Hibernate: drop table if exists event_detail CASCADE
Hibernate: drop table if exists event_reserves CASCADE
Hibernate: drop sequence if exists hibernate_sequence
2022-11-23 08:10:26.292 INFO 2044 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-3 - Shutdown initiated...
2022-11-23 08:10:26.724 INFO 2044 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-3 - Shutdown completed.
2022-11-23 08:10:27.229 INFO 2044 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-11-23 08:10:27.341 INFO 2044 --- [ionShutdownHook] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
Hibernate: drop table if exists account CASCADE
Hibernate: drop table if exists event_detail CASCADE
Hibernate: drop table if exists event_reserves CASCADE
Hibernate: drop sequence if exists hibernate_sequence
2022-11-23 08:10:28.347 INFO 2044 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-4 - Shutdown initiated...
2022-11-23 08:10:28.720 INFO 2044 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-4 - Shutdown completed.
2022-11-23 08:10:28.788 INFO 2044 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-11-23 08:10:28.824 INFO 2044 --- [ionShutdownHook] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
Hibernate: drop table if exists account CASCADE
Hibernate: drop table if exists event_detail CASCADE
Hibernate: drop table if exists event_reserves CASCADE
Hibernate: drop sequence if exists hibernate_sequence
2022-11-23 08:10:29.814 INFO 2044 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-5 - Shutdown initiated...
2022-11-23 08:10:30.036 INFO 2044 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-5 - Shutdown completed.
2022-11-23 08:10:31.091 INFO 2044 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-11-23 08:10:31.140 INFO 2044 --- [ionShutdownHook] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
Hibernate: drop table if exists account CASCADE
Hibernate: drop table if exists event_detail CASCADE
Hibernate: drop table if exists event_reserves CASCADE
Hibernate: drop sequence if exists hibernate_sequence
2022-11-23 08:10:32.435 INFO 2044 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-6 - Shutdown initiated...
2022-11-23 08:10:33.090 INFO 2044 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-6 - Shutdown completed.
> Task :asciidoctor NO-SOURCE
> Task :bootJarMainClassName
> Task :bootJar
> Task :assemble
> Task :check
> Task :build
BUILD SUCCESSFUL in 1h 32s
8 actionable tasks: 7 executed, 1 up-to-date
Build step 'Invoke Gradle script' changed build result to SUCCESS
SSH: Connecting from host [ac65d9d87812]
SSH: Connecting with configuration [spring-server] ...
SSH: EXEC: completed after 202 ms
SSH: Disconnecting configuration [spring-server] ...
SSH: Transferred 2 file(s)
Finished: SUCCESS
결과적으로 배포하고자 했던 컨테이너에 배포 됨을 확인했습니다. 'Use Gradle Wrapper' 사용에 대해서는 조금 더 찾아봐야 할듯합니다.
참고자료