-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
44 lines (37 loc) · 1.71 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
node {
def project = 'umapp-cluster'
def appName = 'expressapp'
def feSvcName = "expressapp"
def imageTag = "shahzeb799/${appName}:latest"
checkout scm
stage 'Docker Login'
sh("docker login --username=shahzeb799 --password=***")
stage 'Build image'
sh("docker build -t ${imageTag} .")
stage 'Push image to registry'
sh("docker push ${imageTag}")
stage "Clean Deployments"
sh("kubectl delete deployment ${appName} --namespace=production")
sh("kubectl delete service ${appName} --namespace=production")
stage "Deploy Application"
switch (env.BRANCH_NAME) {
case "master":
// Change deployed image in canary to the one we just built
sh("kubectl --namespace=production apply -f k8s/services/")
sh("kubectl --namespace=production apply -f k8s/production/")
sh("echo http://`kubectl --namespace=production get service/expressapp --output=json | jq -r '.status.loadBalancer.ingress[0].ip'` > ${feSvcName}")
break
case "develop":
// Change deployed image in canary to the one we just built
sh("kubectl --namespace=production apply -f k8s/services/")
sh("kubectl --namespace=production apply -f k8s/production/")
sh("echo http://`kubectl --namespace=production get service/${feSvcName} --output=json | jq -r '.status.loadBalancer.ingress[0].ip'` > ${feSvcName}")
break
// Roll out a dev environment
default:
sh("kubectl --namespace=production apply -f k8s/services/")
sh("kubectl --namespace=production apply -f k8s/production/")
sh("echo http://`kubectl --namespace=production get service/expressapp --output=json | jq -r '.status.loadBalancer.ingress[0].ip'` > ${feSvcName}")
break
}
}