-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJenkinsfile.native
71 lines (65 loc) · 2.11 KB
/
Jenkinsfile.native
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
podTemplate(label: "mymaven-native",
yaml: """
apiVersion: v1
kind: Pod
spec:
containers:
- name: maven
image: rafabene/jenkins-slave-native
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: /tmp/m2
"""
) {
properties([pipelineTriggers([pollSCM('*/1 * * * * ')])])
node ("mymaven-native"){
container("maven"){
stage ('SCM checkout'){
echo 'Checking out git repository'
git poll: true, url: 'https://github.com/rafabene/microservices4demo'
}
stage ('Maven native build'){
echo 'Building native binary'
dir('hello') {
sh 'mvn package -Pnative -DskipTests'
}
}
stage ('Docker image build'){
echo 'Building docker image'
dir('hello') {
sh 'docker build -t rafabene/ms4demo:java -f src/main/docker/Dockerfile.native .'
}
}
stage ('Perform Tests'){
echo 'Building native binary'
dir('hello') {
sh 'mvn test'
}
}
stage ('Wait for approval'){
input 'Approve deployment?'
}
stage ('Deploy'){
echo 'Building native binary'
dir('hello') {
sh 'kubectl create namespace microservices || echo "Namespace \"microservices\" already exists"'
sh 'kubectl apply -f kubernetes/deployment.yaml'
sh 'kubectl apply -f kubernetes/service.yaml'
sh """kubectl patch deployment hello -n microservices -p '{"spec":{"template":{"metadata":{"labels":{ "build": "${env.BUILD_NUMBER}"}}}}}' """
}
}
}
}
}