forked from vfarcic/go-demo-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
96 lines (94 loc) · 2.28 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
import java.text.SimpleDateFormat
def props
def label = "jenkins-slave-${UUID.randomUUID().toString()}"
currentBuild.displayName = new SimpleDateFormat("yy.MM.dd").format(new Date()) + "-" + env.BUILD_NUMBER
podTemplate(
label: label,
namespace: "go-demo-3-build", // Not allowed with declarative
serviceAccount: "build",
yaml: """
apiVersion: v1
kind: Pod
spec:
containers:
- name: helm
image: vfarcic/helm:2.9.1
command: ["cat"]
tty: true
volumeMounts:
- name: build-config
mountPath: /etc/config
- name: kubectl
image: vfarcic/kubectl
command: ["cat"]
tty: true
- name: golang
image: golang:1.9
command: ["cat"]
tty: true
volumes:
- name: build-config
configMap:
name: build-config
"""
) {
node(label) {
stage("build") {
container("helm") {
sh "cp /etc/config/build-config.properties ."
props = readProperties interpolate: true, file: "build-config.properties"
}
node("docker") { // Not allowed with declarative
checkout scm
k8sBuildImageBeta(props.image)
}
}
stage("func-test") {
try {
container("helm") {
checkout scm
k8sUpgradeBeta(props.project, props.domain, "--set replicaCount=2 --set dbReplicaCount=1")
}
container("kubectl") {
k8sRolloutBeta(props.project)
}
container("golang") {
k8sFuncTestGolang(props.project, props.domain)
}
} catch(e) {
error "Failed functional tests"
} finally {
container("helm") {
k8sDeleteBeta(props.project)
}
}
}
if ("${BRANCH_NAME}" == "master") {
stage("release") {
node("docker") {
k8sPushImage(props.image)
}
container("helm") {
k8sPushHelm(props.project, props.chartVer, props.cmAddr)
}
}
stage("deploy") {
try {
container("helm") {
k8sUpgrade(props.project, props.addr)
}
container("kubectl") {
k8sRollout(props.project)
}
container("golang") {
k8sProdTestGolang(props.addr)
}
} catch(e) {
container("helm") {
k8sRollback(props.project)
}
}
}
}
}
}