-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
113 lines (106 loc) · 2.92 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
#!/usr/bin/env groovy
pipeline {
agent {
kubernetes {
cloud 'SLKE'
workspaceVolume persistentVolumeClaimWorkspaceVolume(claimName: 'workspace-claim', readOnly: false)
defaultContainer 'maven'
yaml """
kind: Pod
spec:
# All containers should have the same UID
securityContext:
runAsUser: 0
containers:
- name: maven
image: harbor.softleader.com.tw/library/maven:3-eclipse-temurin-11
imagePullPolicy: Always
command: ['cat']
tty: true
resources:
limits:
memory: "1Gi"
cpu: "2"
volumeMounts:
- name: m2
mountPath: /root/.m2
- 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
"""
}
}
environment {
MAVEN_OPTS="-Xmx768m -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!"'
}
}
}
// 用當前 pom.xml 定義的 java, spring 版本執行測試,這個組合也會是 release 時所使用的
stage('Unit Testing') {
steps {
sh "make test"
}
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: "@matt",
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}"
)
}
}
}
}
}