forked from azipory/openshift-bluegreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
85 lines (77 loc) · 2.41 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
import java.text.SimpleDateFormat;
// This pipeline expects a paramater newcolor which will set the newcolor of the newly deployed application.
node {
// Blue/Green Deployment into Production
// -------------------------------------
def project = ""
def dest = "example-green"
def active = ""
def newcolor = ""
switch (BUILD_NUMBER.toInteger() % 10) {
case 1:
newcolor="red"
break
case 2:
newcolor="maroon"
break
case 3:
newcolor="yellow"
break
case 4:
newcolor="magenta"
break
case 5:
newcolor="purple"
break
case 6:
newcolor="orange"
break
case 7:
newcolor="cyan"
break
case 8:
newcolor="navy"
break
case 9:
newcolor="green"
break
case 0:
newcolor="blue"
break
}
stage('Determine Deployment color') {
// Determine current project
sh "oc get project|grep -v NAME|awk '{print \$1}' >project.txt"
project = readFile('project.txt').trim()
sh "oc get route example -n ${project} -o jsonpath='{ .spec.to.name }' > activesvc.txt"
// Determine currently active Service
active = readFile('activesvc.txt').trim()
if (active == "example-green") {
dest = "example-blue"
}
echo "Active svc: " + active
echo "Dest svc: " + dest
echo "New color: " + newcolor
}
stage('Build new version') {
// Building in this case means simply changing the environment
// variable newcolor in the deployment configuration.
// There is not Build Configuration since this is a straight
// up Docker Image deployment.
echo "Building ${dest}"
sh "oc set env dc ${dest} COLOR=${newcolor}"
}
stage('Deploy new Version') {
echo "Deploying to ${dest}"
openshiftDeploy depCfg: dest, namespace: project, verbose: 'false', waitTime: '', waitUnit: 'sec'
openshiftVerifyDeployment depCfg: dest, namespace: project, replicaCount: '1', verbose: 'false', verifyReplicaCount: 'true', waitTime: '', waitUnit: 'sec'
openshiftVerifyService namespace: project, svcName: dest, verbose: 'false'
}
stage('Switch over to new Version') {
input "Switch Production?"
sh 'oc patch route example -p \'{"spec":{"to":{"name":"' + dest + '"}}}\''
sh 'oc get route example > oc_out.txt'
oc_out = readFile('oc_out.txt')
echo "Current route configuration: " + oc_out
}
}