-
Notifications
You must be signed in to change notification settings - Fork 4
/
Jenkinsfile
148 lines (144 loc) · 4.89 KB
/
Jenkinsfile
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
library 'cb-shared-lib@main'
def mvnPodYaml = libraryResource 'podtemplates/maven/pod.yml'
def kubectlPodYaml = libraryResource 'podtemplates/kubectl.yml'
environment {
SONAR_CRED = credentials('thunder-sonar')
controllerPodName = ''
}
pipeline {
agent any
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
skipDefaultCheckout true
preserveStashes(buildCount: 10)
}
stages {
stage('Extract Controller Pod Name from Logs') {
steps {
script {
env.controllerPodName = System.getenv('HOSTNAME')
echo "Controller Pod Name extracted: ${env.controllerPodName}"
}
}
}
stage('Build & Scan') {
agent{
kubernetes {
inheritFrom 'maven-app'
yaml mvnPodYaml
}
}
stages{
stage('HA Maven Build Realtime') {
parallel {
stage('Maven Build') {
steps {
checkout scm
container('open-jdk17'){
sh 'ls'
sh 'java --version'
sh 'echo $HOME'
sh './mvnw clean package -Dcheckstyle.skip'
sh 'ls -l /home/jenkins/agent/workspace/spring-petclinic_main/target/'
stash name: 'petclinic-jar', includes: 'target/spring-petclinic-3.3.0-SNAPSHOT.jar '
}
}
}
stage('Kubectl Pod Cleanup') {
agent {
kubernetes {
inheritFrom 'kubectl'
yaml kubectlPodYaml
}
}
steps {
container('kubectl') {
script {
echo "Current controller pod name is: ${controllerPodName}"
sh "sleep 30" //wait for maven checkout to progress
sh "kubectl delete pod ${controllerPodName}" //delete controller pod to simulate HA cutover action
}
}
}
}
}
}
stage('SonarQube Analysis') {
steps {
checkout scm
container('open-jdk17'){
withCredentials([string(credentialsId: 'thunder-sonar', variable: 'SONAR_SECRET')]) {
sh "./mvnw sonar:sonar \
-Dsonar.sourceEncoding=UTF-8 \
-Dsonar.language=java \
-Dsonar.projectKey=petclinic-1 \
-Dsonar.host.url=https://sonarqube.cb-demos.io \
-Dsonar.login=${SONAR_SECRET} \
-Dsonar.projectName=petclinic-1 \
-Dsonar.tests=src/test \
-Dsonar.sources=src/main \
-Dsonar.junit.reportsPath=target/surefire-reports \
-Dsonar.surefire.reportsPath=target/surefire-reports \
-Dsonar.jacoco.reportPath=target/jacoco.exec \
-Dsonar.java.binaries=target/classes \
-Dsonar.java.coveragePlugin=jacoco"
}
}
}
}
}
}
stage('CheckMarx Results') {
steps {
writeFile(
file: "checkmarx.json",
text: '''\
[{
"TotalIssues": 6,
"HighIssues": 0,
"MediumIssues": 1,
"LowIssues": 5,
"InfoIssues": 0,
"SastIssues": 6,
"KicsIssues": 0,
"ScaIssues": -1,
"APISecurity": {
"api_count": 0,
"total_risks_count": 0,
"risks": null
},
"RiskStyle": "medium",
"RiskMsg": "Medium Risk",
"Status": "Completed",
"ScanID": "8a072853-9594-47e5-a544-d6b2d4af837c",
"ScanDate": "",
"ScanTime": "",
"CreatedAt": "2023-07-06, 13:04:53",
"ProjectID": "e34d40c7-cd4b-4cba-9794-0004f66a173e",
"BaseURI": "https://ast.checkmarx.net/projects/e34d40c7-cd4b-4cba-9794-0004f66a173e/overview",
"Tags": {},
"ProjectName": "bws_enterpriseservices",
"BranchName": "testing-2",
"ScanInfoMessage": "",
"EnginesEnabled": [
"sast"
]
}]'''.stripIndent()
)
} // mock out CheckMarx results
}
stage('Publish') {
agent any
steps {
unstash 'petclinic-jar'
echo "Publish petclinic-jar to Nexus"
}
}
stage('Trigger Release') {
agent any
steps {
echo "Deploy petclinic-jar to GCP"
}
}
} //close stages
} //pipeline conclusion