-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.DeployService
executable file
·74 lines (66 loc) · 2.5 KB
/
Jenkinsfile.DeployService
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
pipeline {
agent {
label 'maven'
}
parameters {
choice(name: 'namespace', choices: ['staging', 'production'], description: 'where to deploy')
choice(name: 'service', choices: ['front-end', 'order-service', 'customer-service', 'catalog-service', 'payment-service'], description: 'what service to deploy')
string(name: 'version', defaultValue: '1', description: 'what version to deploy')
string(name: 'registry', defaultValue: '', description: 'Dockerhub account with Docker Images')
}
stages {
stage("deploy") {
environment {
image = "${params.registry}/${params.service}:${params.version}"
kubeservice = sh(script: "echo ${service} | cut -d'-' -f1" , returnStdout: true).trim()
}
steps {
container('kubectl') {
echo "============================================="
echo "Deployment configuration"
echo "namespace : ${params.namespace}"
echo "service : ${params.service}"
echo "version : ${params.version}"
echo "registry : ${params.registry}"
echo "image : ${env.image}"
echo "kubeservice : ${env.kubeservice}"
echo "============================================="
checkout scm
sh "sed -i 's/REPLACE_NAMESPACE/${env.namespace}/g' ${params.service}.yml"
sh "sed -i 's#REPLACE-IMAGE-NAME#${env.image}#g' ${params.service}.yml"
sh "cat ${params.service}.yml"
echo "kubectl apply"
sh "kubectl -n ${params.namespace} apply -f ${params.service}.yml"
echo "Wait for service to start"
sleep 10
echo "get my pod details"
script {
if ( params.service == "front-end") {
sh "kubectl get pods -l run=front-end -n ${params.namespace}"
}
else {
sh "kubectl get pods -l run=${env.kubeservice} -n ${params.namespace}"
}
}
}
container('curl') {
script {
echo "execute a couple of CURL commands"
if ( params.service == "front-end") {
executeCurl(2, "http://front-end.${params.namespace}:80")
}
else {
executeCurl(2, "http://${env.kubeservice}.${params.namespace}:8080")
}
}
}
}
}
}
}
def executeCurl(iterations, url) {
for (int i = 0; i < iterations; i++) {
sh "echo calling ${url}"
sh "curl ${url} -f"
}
}