-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspring-build-image.groovy
88 lines (85 loc) · 1.8 KB
/
spring-build-image.groovy
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
/**
* 本範例展示如何將一個 spring boot 專案打包成 image
*/
pipeline {
agent {
kubernetes {
cloud 'SLKE'
yaml """
kind: Pod
spec:
# All containers should have the same UID
securityContext:
runAsUser: 0
containers:
- name: curl
image: curlimages/curl
command: ['cat']
tty: true
volumeMounts:
- name: shared-data
mountPath: /data
- name: maven
image: harbor.softleader.com.tw/library/maven:3-eclipse-temurin-11
command: ['cat']
tty: true
volumeMounts:
- name: shared-data
mountPath: /data
- name: m2
mountPath: /root/.m2
- name: dockersock
mountPath: /var/run/docker.sock
- name: docker
image: docker:dind
command: ['cat']
tty: true
resources:
limits:
memory: "100Mi"
cpu: "100m"
volumeMounts:
- name: dockersock
mountPath: /var/run/docker.sock
volumes:
- name: shared-data
emptyDir: {}
- name: m2
persistentVolumeClaim:
claimName: m2-claim
- name: dockersock
hostPath:
path: /var/run/docker.sock
"""
}
}
environment {
DATA="/data"
IMAGE_NAME="jenkins-pipeline-examples/spring-build-image:1.0.0"
}
stages {
stage ('Download source code') {
steps {
container('curl') {
sh """
curl -SL https://start.spring.io/starter.zip -d javaVersion=11 -o ${DATA}/demo.zip
unzip ${DATA}/demo.zip -d ${DATA}
rm -f ${DATA}/demo.zip
"""
}
}
}
stage ('Compile and build image') {
steps {
container('maven') {
sh """
mvn -f ${DATA}/pom.xml spring-boot:build-image -Dspring-boot.build-image.imageName=${IMAGE_NAME}
"""
}
container('docker') {
sh "docker rmi -f ${IMAGE_NAME}"
}
}
}
}
}