What is CI CD pipeline?
1
2
3
a series of steps that must be performed
in order to deliver a new version of software
(bulding > testing > deploying)
CI
- Continous Integration
helps developers merge and test code more frequently, even on a daily basis. CI requires that all tests are automated.
CD
- Continuous Deployment / Conitnous Delivery
the next step in the process where the tested code from continuous integration is automatically deployed in various environments by a manual trigger. In continuous delivery, developers need to push changes to their production environment manually.
Benefits
Less risk: automated tests reduce the chance of introducing bugs, creating a safety net that increases the developer’s confidence in their code.
More frequent releases: the automation provided by continuous delivery and continuous deployment allows developers to release and deploy software safely many times per day.
Improved productivity: freed from the manual labor of building and testing the code, developers can focus on the creative aspects of coding.
Elevated quality: CI acts as a quality gate, preventing code that is not up to standards from getting released.
Better design: the iterative nature of continuous integration lets developers work in small increments, allowing a higher degree of experimentation, which leads to more innovative ideas.
- reference : https://www.youtube.com/watch?v=0Emq5FypiMM
Example
- reference : https://crispyblog.kr/development/common/8
Example) Jenkins
Unit Test (In Java case : Jacoco + JUnit)
jacoco
- a library checking Java code coverage
- 테스트코드를 돌리고 그 커버리지 결과를 눈으로 보기 좋도록 html이나 xml, csv 같은 리포트로 생성합니다.
- 테스트 결과가 내가 설정한 커버리지 기준을 만족하는지 확인하는 기능도 있습니다.
- import to Gradle configuration
jacocoTestReport
- binary coverage 결과를 사람이 보기 편한 형태의 report로 저장(html, xml, csv…)
jacocoTestCoverageVerification
- 내가 원하는 coverage 기준을 설정
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
jacocoTestReport {
reports {
// 원하는 리포트를 켜고 끌 수 있습니다.
html.enabled true
xml.enabled false
csv.enabled false
// 각 리포트 타입 마다 리포트 저장 경로를 설정할 수 있습니다.
// html.destination file("$buildDir/jacocoHtml")
// xml.destination file("$buildDir/jacoco.xml")
// dependsOn으로 실행 순서 지정 가능
dependsOn (`:test`,
`:jacocoTestReport`,
`:jacocoTestCoverageVerification`)
}
}
jacocoTestCoverageVerification {
violationRules {
rule {
element = 'CLASS'
limit {
counter = 'BRANCH'
value = 'COVEREDRATIO'
minimum = 0.90
}
}
}
}
// default
test {
jacoco {
enabled = true
destinationFile = file("$buildDir/jacoco/$.exec")
includes = []
excludes = []
excludeClassLoaders = []
includeNoLocationClasses = false
sessionId = "<auto-generated value>"
dumpOnExit = true
classDumpDir = null
output = JacocoTaskExtension.Output.FILE
address = "localhost"
port = 6300
jmx = false
}
}
- reference : «https://techblog.woowahan.com/2661/>
JUnit
- a simple Java unit testing framework
- Annotations
- @Test
- @BeforeEach
- @AfterEach
- @DisplayName
- Assert…
- assertEquals
- asssertThat().isEqualsTo()
- assertAll
** vs org.springframework.util.Assert - not for test code - often used to parameter verification
build.gradle
1
2
3
test {
useJUnitPlatform()
}
Test.java
1
2
3
4
5
6
7
8
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
public class CaluratorTest { @Test
public void testSum() {
// ...
Assertions.assertEquals(...);
}}
- reference :
https://phoenixnap.com/kb/what-is-jenkins
Example) Gitlab CI/CD
Use .gitlab-ci.yml
for automation
- how to make [.gitlab-ci.yml]
Comments powered by Disqus.