목표 : 서버(시놀로지) - 젠킨스(시놀로지, 도커) - 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 로 사용에 맞게 수정한다.
[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)