-
Notifications
You must be signed in to change notification settings - Fork 407
/
Copy pathJenkinsfile.canary
72 lines (70 loc) · 2.07 KB
/
Jenkinsfile.canary
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
@Library('dynatrace@master') _
def tagMatchRules = [
[
meTypes: [
[meType: 'SERVICE']
],
tags : [
[context: 'CONTEXTLESS', key: 'app', value: 'front-end'],
[context: 'CONTEXTLESS', key: 'environment', value: 'production']
]
]
]
pipeline {
parameters {
string(name: 'VERSION1', description: 'Percentage of traffic to be routed to version 1', trim: true)
string(name: 'VERSION2', description: 'Percentage of traffic to be routed to version 2', trim: true)
string(name: 'REMEDIATIONURL', description: 'Remediation script to call if canary release fails', trim: true)
}
agent {
label 'kubegit'
}
stages {
stage('Update yml files') {
when {
beforeAgent true
expression {
return (env.VERSION1 != "" && env.VERSION2 != "")
}
}
steps {
container('kubectl') {
sh "sed -i \"s~weight: .* #v1~weight: ${env.VERSION1} #v1~\" istio/virtual_service_canary.yml"
sh "sed -i \"s~weight: .* #v2~weight: ${env.VERSION2} #v2~\" istio/virtual_service_canary.yml"
}
}
}
stage('Deploy updated yml') {
when {
beforeAgent true
expression {
return (env.VERSION1 != "" && env.VERSION2 != "")
}
}
steps {
container('kubectl') {
sh "cat istio/virtual_service_canary.yml"
sh "kubectl apply -f istio/virtual_service_canary.yml -n default"
sh "kubectl describe virtualservices sockshop -n default"
}
}
}
stage('Update configuration change') {
steps {
container("curl") {
script {
def status = pushDynatraceConfigurationEvent (
tagRule : tagMatchRules,
description : "Load balancing changed to: v1 ${env.VERSION1} % ; v2 ${env.VERSION2} %",
source : "Jenkins",
configuration : "Load Balancer",
customProperties : [
[key: 'remediationAction', value: "${env.REMEDIATIONURL}"]
]
)
}
}
}
}
}
}