-
Notifications
You must be signed in to change notification settings - Fork 2
/
groovy_task6.txt
94 lines (82 loc) · 2.07 KB
/
groovy_task6.txt
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
92
93
94
job("task6_job1_gitpull") {
description ("it will pull code from GitHub")
scm{
github('Dakshjain1/task_2','master')
}
triggers {
githubPush()
}
steps {
shell('sudo cp -rvf * /djtask3')
}
}
job("task6_job2_launchpod") {
description ("It will create the pods")
label('kubectl')
triggers {
upstream('task6_job1_gitpull', 'SUCCESS')
}
steps {
shell('''cd /root/.kube
python3 prog.py
export count=$(kubectl get deployments | grep webserver | wc -l)
echo $count
if [ $count -eq 1 ]
then
echo "Pod is already running"
kubectl replace -f /root/.kube/website_deploy.yaml
else
kubectl create -f /root/.kube/website_deploy.yaml
kubectl create -f /root/.kube/website_service.yaml
fi''')
}
}
job("task6_job3_testapp") {
description ("It will test if pod is running else send a mail")
triggers {
upstream('task6_job2_launchpod', 'SUCCESS')
}
steps {
shell('''if sudo kubectl get deployments webserver
then
echo "send to production"
else
echo "sending back to developer"
exit 1
fi''')
}
publishers {
extendedEmail {
recipientList('[email protected]')
defaultSubject('Failed build')
defaultContent('The build was failed')
contentType('text/html')
triggers {
failure{
attachBuildLog(true)
subject('Failed build')
content('The build was failed')
sendTo {
developers()
}
}
}
}
}
}
job("task6_job4_monitor_launch") {
description ("It will launch on production env")
triggers {
upstream('task6_job3_testapp', 'SUCCESS')
}
steps {
shell('curl 192.168.99.100:31001')
}
}
buildPipelineView('groovy-task6') {
title('groovy_task6')
displayedBuilds(5)
selectedJob('task6_job1_gitpull')
showPipelineParameters(true)
refreshFrequency(3)
}