-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
85 lines (82 loc) · 2.53 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
pipeline {
agent {
label 'maven'
}
stages {
stage('Build Image') {
steps {
script {
openshift.withCluster() {
def bc = openshift.startBuild("gateway-canary")
bc.logs('-f')
}
}
}
}
stage('Deploy Canary') {
steps {
script {
openshift.withCluster() {
def dc = openshift.selector("dc", "gateway")
dc.rollout().latest()
dc.rollout().status()
sh "oc set route-backends gateway gateway=90 gateway-canary=10"
}
}
}
}
stage('Verify Canary') {
steps {
script {
promoteOrRollback = input message: 'Promote or rollback canary deployment?',
parameters: [choice(name: "Promote or Rollback?", choices: 'Promote\nRollback', description: '')]
}
}
}
stage("Rollback canary"){
when{
expression {
return promoteOrRollback == 'Rollback'
}
}
steps{
echo "Rollback for canary deployment."
script {
openshift.withCluster {
openshift.withProject('user3') {
openshift.selector('dc', 'gateway-canary').rollout().undo()
//wait for rollout
openshift.selector('dc', 'gateway-canary').rollout().status()
//set canary imagestream back to production tag
openshift.tag("coolstore/gateway:latest", "user3/gateway-canary:latest")
}
}
}
}
}
stage("Production deployment") {
when{
expression {
return promoteOrRollback != 'Rollback' //Promote or null (first deployment)
}
}
steps {
script {
openshift.withCluster() {
openshift.withProject('user3') {
//Tag latest from build namespace
openshift.tag("user3/gateway-canary:latest", "user3/gateway:latest")
/***
* Rollout
***/
openshift.selector('dc', 'gateway').rollout().latest()
//wait for rollout. It waits until pods are running (if readiness probe is set)
openshift.selector('dc', 'gateway').rollout().status()
sh "oc set route-backends gateway gateway=100 gateway-canary=0"
}
}
}
}
}
}
}