-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
111 lines (101 loc) · 3.55 KB
/
Copy pathJenkinsfile
File metadata and controls
111 lines (101 loc) · 3.55 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
pipeline {
agent any
environment {
AWS_REGION = 'ap-northeast-2'
ECR_REPO = '605134473022.dkr.ecr.ap-northeast-2.amazonaws.com/olive-back'
IMAGE_TAG = 'latest'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build JAR') {
steps {
sh 'chmod +x gradlew' // gradlew에 실행 권한을 부여
sh './gradlew clean build' // Gradle 빌드 수행
}
}
// OWASP Dependency Check
// stage('OWASP Dependency-Check Vulnerabilities') {
// steps {
// dir("src"){
// dependencyCheck additionalArguments: '''
// -o './'
// -s './'
// -f 'ALL'
// --nvd-mirror https://mirror.nvd.nist.gov
// --caches './dependency-check-cache'
// --prettyPrint''', odcInstallation: 'owasp'
// dependencyCheckPublisher pattern: 'dependency-check-report.xml'
// }
// }
// }
//
// SonarQube 분석
stage('SonarQube Scanner') {
steps {
withSonarQubeEnv('jg-sonarqube') {
sh "./gradlew sonar"
}
}
}
// image build
stage('Build Image') {
steps {
script {
docker.withRegistry("https://${ECR_REPO}/", '9b45eaf4-a184-44eb-ba8c-8e20a854de1b') {
myapp = docker.build('olive-back')
}
}
}
}
// iamge push
stage('Push Image to ECR') {
steps {
script {
docker.withRegistry("https://${ECR_REPO}/", '9b45eaf4-a184-44eb-ba8c-8e20a854de1b') {
myapp.push("${IMAGE_TAG}")
}
}
}
}
// image scan ( Trivy )
stage('Scan Image with Trivy') {
steps {
script {
try {
// Trivy로 이미지 스캔하고 HTML 리포트 생성
sh 'trivy image --format template --template "@/root/html.tpl" --output trivy-report.html "${ECR_REPO}:${IMAGE_TAG}"'
echo "Trivy scan completed"
} catch (Exception e) {
echo "Trivy scan failed: ${e.getMessage()}"
currentBuild.result = 'FAILURE'
throw e
}
}
}
}
stage('Publish Trivy Report') {
steps {
script {
// HTML 리포트가 존재하는지 확인하고 리포트를 출력
if (fileExists('trivy-report.html')) {
echo "Trivy report found, publishing HTML report"
publishHTML(target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: false,
reportDir: '.',
reportFiles: 'trivy-report.html',
reportName: 'Trivy Vulnerability Report'
])
} else {
echo "Trivy report not found, skipping HTML report publishing"
}
}
}
}
}
}