-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
79 lines (65 loc) · 3.27 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
pipeline {
agent any
stages{
stage('git repo & clean'){
steps {
script {
try {
sh "rm -r helmweb12"
sh "rm -r webchart12"
sh "git clone [email protected]:avivlev98/helmweb12.git"
} catch (Exception e) {
build_ok = true
sh "git clone [email protected]:avivlev98/helmweb12.git"
echo e.toString()
}
}
}
}
stage('Deploy or delete'){
steps{
script {
// Define Variable
def USER_INPUT = input(
message: 'Are you want to Deploy/Upgrade or to Delete the chart ?',
parameters: [
[$class: 'ChoiceParameterDefinition',
choices: ['Deploy/Upgrade Chart','Delete Chart'].join('\n'),
name: 'input',
description: 'Menu - select box option']
])
echo "The answer is: ${USER_INPUT}"
if( "${USER_INPUT}" == "Deploy/Upgrade Chart"){
kubeconfig(caCertificate: '', credentialsId: 'chartkube', serverUrl: 'https://devops-interview-0b426a9d.hcp.westeurope.azmk8s.io:443') {
sh '''
CHART=webchart12/
NAMESPACE=aviv
PACKAGE=avivwebchart12
cd /var/lib/jenkins/workspace/helmpipe/helmweb12/
DEPLOYED=$(helm list -n $NAMESPACE |grep -E "^${PACKAGE}" |grep deployed |wc -l)
if [ $DEPLOYED -eq 0 ] ; then
#cd /var/lib/jenkins/workspace/helmpipe/helmweb12/
helm install ${PACKAGE} ${CHART} -n $NAMESPACE
else
helm upgrade ${PACKAGE} ${CHART} -n $NAMESPACE
fi
echo "deployed!"
'''
}
} else {
//do something else
kubeconfig(caCertificate: '', credentialsId: 'chartkube', serverUrl: 'https://devops-interview-0b426a9d.hcp.westeurope.azmk8s.io:443') {
sh '''
CHART=webchart12/
NAMESPACE=aviv
PACKAGE=avivwebchart12
cd /var/lib/jenkins/workspace/helmpipe/helmweb12/
helm uninstall ${PACKAGE} -n $NAMESPACE
'''
}
}
}
}
}
}
}