-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
139 lines (131 loc) · 3.48 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
#!/usr/bin/env groovy
pipeline {
agent {
kubernetes {
cloud 'SLKE'
workspaceVolume persistentVolumeClaimWorkspaceVolume(claimName: 'workspace-claim', readOnly: false)
defaultContainer 'maven-java11'
yaml """
kind: Pod
spec:
# All containers should have the same UID
securityContext:
runAsUser: 0
containers:
- name: maven-java11
image: harbor.softleader.com.tw/library/maven:3-eclipse-temurin-11
imagePullPolicy: Always
command: ['cat']
tty: true
resources:
limits:
memory: "2.5Gi"
cpu: "2"
volumeMounts:
- name: m2
mountPath: /root/.m2
- name: dockersock
mountPath: /var/run/docker.sock
- name: maven-java17
image: harbor.softleader.com.tw/library/maven:3-eclipse-temurin-17
imagePullPolicy: Always
command: ['cat']
tty: true
resources:
limits:
memory: "2.5Gi"
cpu: "2"
volumeMounts:
- name: m2
mountPath: /root/.m2
- name: dockersock
mountPath: /var/run/docker.sock
- name: git
image: alpine/git:v2.32.0
command: ['cat']
tty: true
resources:
limits:
memory: "100Mi"
cpu: "100m"
volumes:
- name: m2
persistentVolumeClaim:
claimName: m2-claim
- name: dockersock
hostPath:
path: /var/run/docker.sock
"""
}
}
environment {
MAVEN_OPTS="-Xmx2048m -XX:MaxMetaspaceSize=128m"
}
stages {
stage('Confirm Env') {
steps {
container('git') {
script {
env.LAST_COMMIT_AUTHOR_NAME = sh(
script: 'git --no-pager show -s --format=%an',
returnStdout: true
).trim()
env.LAST_COMMIT_AUTHOR_EMAIL = sh(
script: 'git --no-pager show -s --format=%ae',
returnStdout: true
).trim()
env.LAST_COMMIT_TIME = sh(
script: 'git --no-pager show -s --date=format:"%Y/%m/%d %T" --format=%ad',
returnStdout: true
).trim()
}
}
sh 'printenv'
sh 'java -version'
sh 'mvn --version'
echo "${params}"
}
}
stage('Compile and Style Check') {
steps {
sh "make compile"
container('git') {
sh '[ ! -z "$(git status -s)" ] && exit 1 || echo "Good to go!"'
}
}
}
stage('Style Check (Spring 2, Java 11)') {
steps {
sh "make test"
}
}
stage('Unit Testing (Spring 3, Java 17)') {
steps {
container('maven-java17') {
sh "make test JAVA=17 SPRING=3.3.2"
}
}
post {
always {
junit "**/target/surefire-reports/**/*.xml"
}
}
}
}
post {
failure {
script {
if (env.BRANCH_NAME == 'main'
// 若短時間太密集的 push, 之前的 job 會被 jenkins 中斷, 這樣就可能會就連第一步都還沒執行的狀況, 但也算是失敗
// 然而取得 git 資訊就在第一步, 所以至少要第一步都有執行完才發佈 slack 吧
&& env.LAST_COMMIT_AUTHOR_NAME && env.LAST_COMMIT_AUTHOR_EMAIL && env.LAST_COMMIT_TIME) {
slackSend(
color: "danger",
channel: "dept-rd",
message: "Attention @here, The pipeline <$BUILD_URL|*${env.JOB_NAME} #${env.BUILD_NUMBER}*> has failed! :omg:\n>Last commit by ${env.LAST_COMMIT_AUTHOR_NAME} (${env.LAST_COMMIT_AUTHOR_EMAIL}) @ ${env.LAST_COMMIT_TIME}"
)
}
}
}
}
}