/
Promote.groovy
91 lines (84 loc) · 2.83 KB
/
Promote.groovy
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
86
87
88
89
90
91
properties([
parameters(
[
stringParam(
name: 'GIT_REPO',
defaultValue: ''
)
]
)
])
def version
def revision
pipeline {
agent {
kubernetes {
label 'deploy-service-pod'
defaultContainer 'jnlp'
yaml """
apiVersion: v1
kind: Pod
metadata:
labels:
job: promote-service
spec:
containers:
- name: git
image: alpine/git
command: ["cat"]
tty: true
- name: helm-cli
image: ibmcom/k8s-helm:v2.6.0
command: ["cat"]
tty: true
"""
}
}
stages {
stage('Find version on staging') {
steps {
container('helm-cli') {
script {
def chart = params.GIT_REPO.toLowerCase()
def chartVersion = sh(script: "/helm history staging-${chart} | grep DEPLOYED | awk '{ print \$8 }'", returnStdout: true).trim()
version = chartVersion.substring(chart.length() + 1)
revision = version.substring(0, 7)
sh "echo 'Promoting revision: ${chart}-${version} staging->production'"
}
}
}
}
stage('Find deployment descriptor') {
steps {
container('git') {
script {
withCredentials([[
$class: 'UsernamePasswordMultiBinding',
credentialsId: 'github',
usernameVariable: 'USERNAME',
passwordVariable: 'PASSWORD'
]]) {
sh "git clone https://$USERNAME:$PASSWORD@github.com/gmandnepr/${params.GIT_REPO}.git"
dir ("${params.GIT_REPO}") {
sh "git checkout ${revision}"
}
}
}
}
}
}
stage('Promote version to production') {
steps {
container('helm-cli') {
script {
dir ("${params.GIT_REPO}") {
sh "./helm/setRevision.sh ${version}"
def registryIp = sh(script: 'getent hosts registry.kube-system | awk \'{ print $1 ; exit }\'', returnStdout: true).trim()
sh "/helm upgrade production-${params.GIT_REPO.toLowerCase()} helm/ --install --namespace production --set registry=${registryIp}"
}
}
}
}
}
}
}