-
Notifications
You must be signed in to change notification settings - Fork 4
/
Jenkinsfile
171 lines (171 loc) · 6.75 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
pipeline{
agent{
kubernetes(label: "jenkins-slave",
yaml: """
apiVersion: v1
kind: Pod
spec:
containers:
- name: slave
image: rafabene/jenkins-slave
imagePullPolicy: IfNotPresent
tty: true
command: ["cat"]
volumeMounts:
- name: dockersock
mountPath: /var/run/docker.sock
- name: m2
mountPath: /root/.m2
volumes:
- name: dockersock
hostPath:
path: /var/run/docker.sock
- name: m2
hostPath:
path: /vagrant/m2
""")
}
parameters {
choice(name: 'JAVA_BUILD_TYPE', choices: ['JVM', 'Native'], description: 'Type of Quarkus build?')
}
triggers {
pollSCM('*/1 * * * * ')
}
stages {
stage ('SCM checkout'){
steps{
echo 'Checking out git repository'
git 'https://github.com/rafabene/microservices4demo'
}
}
stage ('Build both microservices'){
parallel{
stage('Build Hello Service'){
stages{
stage('Maven Build'){
steps{
container('slave'){
echo 'Building Java application using maven'
dir('hello'){
sh 'mvn package -DskipTests'
}
}
}
}
stage('Maven native build'){
when{
expression { params.JAVA_BUILD_TYPE == 'Native' }
}
steps{
container('slave'){
echo 'Building native Java application using maven'
dir('hello'){
sh 'mvn package -Pnative -DskipTests'
}
}
}
}
stage('Docker build'){
when{
expression { params.JAVA_BUILD_TYPE == 'JVM' }
}
steps{
container('slave'){
echo "Building docker image"
dir('hello'){
sh 'docker build -f src/main/docker/Dockerfile.jvm -t rafabene/ms4demo:java .'
}
}
}
}
stage('Docker build with native binary'){
when{
expression { params.JAVA_BUILD_TYPE == 'Native' }
}
steps{
container('slave'){
echo "Building docker image using native binary"
dir('hello'){
sh 'docker build -f src/main/docker/Dockerfile.native -t rafabene/ms4demo:java .'
}
}
}
}
stage('Execute Tests'){
steps{
container('slave'){
echo "Run Tests"
dir('hello'){
sh 'mvn test'
}
}
}
}
}
}
stage('Build Ola Service'){
stages{
stage('NPM Install'){
steps{
container('slave'){
echo 'Running NPM Install'
dir('ola'){
sh 'npm install'
}
}
}
}
stage('Docker build'){
steps{
container('slave'){
echo "Building docker image"
dir('ola'){
sh 'docker build -t rafabene/ms4demo:node .'
}
}
}
}
stage('Execute Tests'){
steps{
container('slave'){
echo "Run Tests"
dir('ola'){
sh 'npm test'
}
}
}
}
}
}
}
}
stage('Integration tests'){
steps{
container('slave'){
echo "Here I execute the Integration tests"
}
}
}
stage('Human approval'){
steps{
input(message: 'Proceed to deployment?')
}
}
stage('Deployment'){
steps{
container('slave'){
sh 'kubectl create namespace microservices || echo "Namespace \"microservices\" already exists"'
sh 'kubectl apply -f hello/kubernetes/deployment.yaml'
sh 'kubectl apply -f ola/kubernetes/deployment.yaml'
sh 'kubectl apply -f ola/kubernetes/deployment-v2.yaml'
sh 'kubectl apply -f hello/kubernetes/service.yaml'
sh 'kubectl apply -f ola/kubernetes/service.yaml'
sh 'kubectl apply -f hello/kubernetes/gateway.yaml -n microservices || echo "Istio not installed"'
sh """kubectl patch deployment hello -n microservices -p '{"spec":{"template":{"metadata":{"labels":{ "build": "${env.BUILD_NUMBER}"}}}}}' """
sh """kubectl patch deployment ola-v1 -n microservices -p '{"spec":{"template":{"metadata":{"labels":{ "build": "${env.BUILD_NUMBER}"}}}}}' """
sh """kubectl patch deployment ola-v2 -n microservices -p '{"spec":{"template":{"metadata":{"labels":{ "build": "${env.BUILD_NUMBER}"}}}}}' """
}
}
}
}
}