forked from RAMKIDEVOPS/CI-with-Jenkins-in-AWS-Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
107 lines (54 loc) · 1.56 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
pipeline {
agent any
environment {
PROJECT_ID = 'devops-vinay-262018'
CLUSTER_NAME = 'k8-cluster1'
LOCATION = 'us-east1-b'
CREDENTIALS_ID = 'k8'
}
stages {
stage("Checkout code") {
steps {
checkout scm
}
}
stage("Build") {
steps {
echo "cleaning and packaging"
sh 'mvn clean package'
}
}
stage("Test") {
steps {
echo "Testing"
sh 'mvn test'
}
}
stage("Build image") {
steps {
script {
myapp = docker.build("vinaymahesh/devops:${env.BUILD_ID}")
}
}
}
stage("Push image") {
steps {
script {
docker.withRegistry('https://registry.hub.docker.com', 'docker') {
myapp.push("${env.BUILD_ID}")
}
}
}
}
stage('Deploy to GKE') {
steps{
echo "Deployment started"
sh 'ls -ltr'
sh 'pwd'
sh "sed -i 's/tagversion/${env.BUILD_ID}/g' deployment.yaml"
step([$class: 'KubernetesEngineBuilder', projectId: env.PROJECT_ID, clusterName: env.CLUSTER_NAME, location: env.LOCATION, manifestPattern: 'deployment.yaml', credentialsId: env.CREDENTIALS_ID, verifyDeployments: true])
echo "Deployment Finished"
}
}
}
}