본문 바로가기
Ops/Synology

Docker에 Jenkins 로 CI/CD 구축(3/4)

by 바람냄새 2023. 8. 15.

------------------------------------------------------------------------------------------------------------------

대주제 : 시놀로지 도커 활용

소주제 : 시놀로지에 젠킨스 설치하여  CI/CD 구축

목표 : 서버(시놀로지) - 젠킨스(시놀로지, 도커) - Git(Github) 환경의 서비스 환경 구축.

-------------------------------------------------------------------------------------------------------------------
Docker에 Jenkins 로 CI/CD 구축(1/4)
Docker에 Jenkins 로 CI/CD 구축(2/4)
Docker에 Jenkins 로 CI/CD 구축(3/4)
 1. 파이프라인 구성을 위한 플러그인 설치
 2. 파이프라인 구성
 3. 빌드실행

Docker에 Jenkins 로 CI/CD 구축(4/4)


 1.  파이프라인 구성을 위한 플러그인 설치

 

 

Pipeline 프로젝트 생성

 

2.  파이프라인 구성

1) Jenkins에 Pipeline Syntax 설정

 

GitHub + Maven  이라는 템플릿을 선택하여 기본 템플릿 스크립트 표시

 

Pipeline Script (수정본)

pipeline {
    agent any

    tools {
        // Install the Maven version configured as "M3" and add it to the path.
        maven "maven-3.8.1"
    }

    stages {
        stage('Build') {
            steps {
                // Get some code from a GitHub repository
                git branch: 'main',url: 'https://github.com/whwnddml/bootdemo.git'

                // Run Maven on a Unix agent.
                sh "mvn -Dmaven.test.failure.ignore=true clean package"

                // To run Maven on a Windows agent, use
                // bat "mvn -Dmaven.test.failure.ignore=true clean package"
            }

            post {
                // If Maven was able to run the tests, even if some of the test
                // failed, record the test results and archive the jar file.
                success {
                    archiveArtifacts 'target/*.jar'
                }
            }
        }
    }
}

tools 의 Maven 항목은 젠킨스 Tools 설정에서 Maven Name으로 설정한 값을 입력한다.

buile 스테이지의 git 은 branch, credentialsId, url 로 사용에 맞게 수정한다.

 

2) Spring Boot 프로젝트에 Jenkinsfile 구성


 


 3.  빌드실행

 

Console Output

 

 

참고 사이트

https://sihyung92.oopy.io/e5300d92-1a4e-40f4-b927-a93b2bbb17d2

https://foot-develop.tistory.com/14

https://velog.io/@sileeee/Jenkins-Pipeline-%EA%B5%AC%EC%84%B1%ED%95%98%EA%B8%B0

https://velog.io/@byeongju/Jenkins%EC%9D%98-Mulitbranch-Pipeline%EC%9D%84-%ED%86%B5%ED%95%9C-CICD

https://blog.naver.com/PostView.nhn?blogId=megaboy1129&logNo=222039630530&parentCategoryNo=&categoryNo=43&viewDate=&isShowPopularPosts=true&from=search

https://hye0-log.tistory.com/45

 

로그 전문

Started by user dev-user Obtained Jenkinsfile from git https://github.com/whwnddml/bootdemo.git [Pipeline] Start of Pipeline [Pipeline] node Running on Jenkins in /var/jenkins_home/workspace/pipeline-test [Pipeline] { [Pipeline] stage [Pipeline] { (Declarative: Checkout SCM) [Pipeline] checkout Selected Git installation does not exist. Using Default The recommended git tool is: NONE No credentials specified > git rev-parse --resolve-git-dir /var/jenkins_home/workspace/pipeline-test/.git # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url https://github.com/whwnddml/bootdemo.git # timeout=10 Fetching upstream changes from https://github.com/whwnddml/bootdemo.git > git --version # timeout=10 > git --version # 'git version 2.30.2' > git fetch --tags --force --progress -- https://github.com/whwnddml/bootdemo.git +refs/heads/*:refs/remotes/origin/* # timeout=10 > git rev-parse refs/remotes/origin/main^{commit} # timeout=10 Checking out Revision fe345cd210d9c3cf1684fd59d03b967ffbb22dc6 (refs/remotes/origin/main) > git config core.sparsecheckout # timeout=10 > git checkout -f fe345cd210d9c3cf1684fd59d03b967ffbb22dc6 # timeout=10 Commit message: "jenkinsfile 추가" > git rev-list --no-walk a599100f59ca922059cd36164d02471c0bb0b7a6 # timeout=10 [Pipeline] } [Pipeline] // stage [Pipeline] withEnv [Pipeline] { [Pipeline] stage [Pipeline] { (Declarative: Tool Install) [Pipeline] tool [Pipeline] envVarsForTool [Pipeline] } [Pipeline] // stage [Pipeline] withEnv [Pipeline] { [Pipeline] stage [Pipeline] { (Build) [Pipeline] tool [Pipeline] envVarsForTool [Pipeline] withEnv [Pipeline] { [Pipeline] git Selected Git installation does not exist. Using Default The recommended git tool is: NONE No credentials specified > git rev-parse --resolve-git-dir /var/jenkins_home/workspace/pipeline-test/.git # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url https://github.com/whwnddml/bootdemo.git # timeout=10 Fetching upstream changes from https://github.com/whwnddml/bootdemo.git > git --version # timeout=10 > git --version # 'git version 2.30.2' > git fetch --tags --force --progress -- https://github.com/whwnddml/bootdemo.git +refs/heads/*:refs/remotes/origin/* # timeout=10 > git rev-parse refs/remotes/origin/main^{commit} # timeout=10 Checking out Revision fe345cd210d9c3cf1684fd59d03b967ffbb22dc6 (refs/remotes/origin/main) > git config core.sparsecheckout # timeout=10 > git checkout -f fe345cd210d9c3cf1684fd59d03b967ffbb22dc6 # timeout=10 > git branch -a -v --no-abbrev # timeout=10 > git branch -D main # timeout=10 > git checkout -b main fe345cd210d9c3cf1684fd59d03b967ffbb22dc6 # timeout=10 Commit message: "jenkinsfile 추가" [Pipeline] sh + mvn -Dmaven.test.failure.ignore=true clean package
[INFO] Scanning for projects... [INFO] [INFO] ------------------------< com.example:bootdemo >------------------------ [INFO] Building bootdemo 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]---------------------------------
[INFO] [INFO] --- maven-clean-plugin:3.2.0:clean (default-clean) @ bootdemo --- [INFO] Deleting /var/jenkins_home/workspace/pipeline-test/target [INFO] [INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ bootdemo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Using 'UTF-8' encoding to copy filtered properties files. [INFO] Copying 1 resource [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ bootdemo --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 2 source files to /var/jenkins_home/workspace/pipeline-test/target/classes
[INFO] [INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ bootdemo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Using 'UTF-8' encoding to copy filtered properties files. [INFO] skip non existing resourceDirectory /var/jenkins_home/workspace/pipeline-test/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ bootdemo --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to /var/jenkins_home/workspace/pipeline-test/target/test-classes [INFO] [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ bootdemo ---
[INFO] [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] -------------------------------------------------------
[INFO] Running com.example.demo.BootdemoApplicationTests 02:12:53.346 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate] 02:12:53.377 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
02:12:53.497 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.example.demo.BootdemoApplicationTests] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper] 02:12:53.530 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.example.demo.BootdemoApplicationTests], using SpringBootContextLoader 02:12:53.541 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.example.demo.BootdemoApplicationTests]: class path resource [com/example/demo/BootdemoApplicationTests-context.xml] does not exist 02:12:53.543 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.example.demo.BootdemoApplicationTests]: class path resource [com/example/demo/BootdemoApplicationTestsContext.groovy] does not exist 02:12:53.544 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.example.demo.BootdemoApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}. 02:12:53.546 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.example.demo.BootdemoApplicationTests]: BootdemoApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration. 02:12:53.678 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.example.demo.BootdemoApplicationTests] 02:12:53.834 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [/var/jenkins_home/workspace/pipeline-test/target/classes/com/example/demo/BootdemoApplication.class] 02:12:53.836 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.example.demo.BootdemoApplication for test class com.example.demo.BootdemoApplicationTests 02:12:54.131 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.example.demo.BootdemoApplicationTests]: using defaults. 02:12:54.132 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener] 02:12:54.167 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/TransactionDefinition] 02:12:54.168 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute] 02:12:54.169 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@2c532cd8, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@294e5088, org.springframework.test.context.event.ApplicationEventsTestExecutionListener@51972dc7, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@3700ec9c, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@2002348, org.springframework.test.context.support.DirtiesContextTestExecutionListener@5911e990, org.springframework.test.context.event.EventPublishingTestExecutionListener@31000e60, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@1d470d0, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@24d09c1, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@54c62d71, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@65045a87, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@47f4e407, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@2d1dee39] 02:12:54.180 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@5e1fa5b1 testClass = BootdemoApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@6b00f608 testClass = BootdemoApplicationTests, locations = '{}', classes = '{class com.example.demo.BootdemoApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@49b2a47d, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@642a7222, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@41f69e84, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@6cc4cdb9, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@5852c06f, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@3c72f59f], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.7.14) 2023-08-14 02:12:55.118 INFO 704 --- [ main] c.example.demo.BootdemoApplicationTests : Starting BootdemoApplicationTests using Java 11.0.20 on jenkins with PID 704 (started by jenkins in /var/jenkins_home/workspace/pipeline-test) 2023-08-14 02:12:55.125 INFO 704 --- [ main] c.example.demo.BootdemoApplicationTests : No active profile set, falling back to 1 default profile: "default"
2023-08-14 02:12:58.865 INFO 704 --- [ main] c.example.demo.BootdemoApplicationTests : Started BootdemoApplicationTests in 4.552 seconds (JVM running for 7.233)
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.655 s - in com.example.demo.BootdemoApplicationTests [INFO] [INFO] Results: [INFO] [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] [INFO] --- maven-jar-plugin:3.2.2:jar (default-jar) @ bootdemo ---
[INFO] Building jar: /var/jenkins_home/workspace/pipeline-test/target/bootdemo-0.0.1-SNAPSHOT.jar [INFO] [INFO] --- spring-boot-maven-plugin:2.7.14:repackage (repackage) @ bootdemo ---
[INFO] Replacing main artifact with repackaged archive [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 15.407 s [INFO] Finished at: 2023-08-14T02:13:01Z [INFO] ------------------------------------------------------------------------ Post stage [Pipeline] archiveArtifacts Archiving artifacts [Pipeline] } [Pipeline] // withEnv
[Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node
[Pipeline] End of Pipeline Finished: SUCCESS