This repository was archived by the owner on Jan 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
171 lines (171 loc) · 7.12 KB
/
Jenkinsfile
File metadata and controls
171 lines (171 loc) · 7.12 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
pipeline {
agent any
options {
buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '30'))
parallelsAlwaysFailFast()
timestamps()
}
stages {
stage('Git') {
steps {
pwd(tmp: true)
sh '''
pwd
ls -l
'''
echo 'Starting to build docker image: Backend Api Portal Server'
script {
docker.build('ubuntu-development:1.0', '--build-arg git_personal_token=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 -f Dockerfile.development .')
sh 'pwd'
sh 'docker run --name ubuntu_dev_CI -dit -p 6200:6200 -p 27017:27017 -v ${PWD}:/Workspace -w="/Workspace" ubuntu-development:1.0 /bin/bash'
sh label:
'Update Repo and start Mongod',
script:'''
echo "Update Repo and start Mongod"
set -x
docker exec -w /Development/ ubuntu_dev_CI pwd
docker exec -w /Development/ ubuntu_dev_CI ls -l
docker exec -w /Development/ ubuntu_dev_CI git pull
docker exec -w /Workspace/Milestone3/ ubuntu_dev_CI rm -rf Binary/
docker exec -w /Workspace/Milestone5/ ubuntu_dev_CI rm -rf Binary/
docker exec -w /Development/Milestone3/ ubuntu_dev_CI sudo mongod --port 27017 --dbpath /srv/mongodb/db0 --replSet rs0 --bind_ip localhost --fork --logpath /var/log/mongod.log
docker exec -w /Development/Milestone3/ ubuntu_dev_CI ps -ef
'''
}
}
post {
failure {
echo "Failed during Git stage"
}
}
}
stage('Build Backend3') {
steps {
script {
echo 'Build Binaries'
sh label:
'Build Binaries',
script:'''
set -x
docker exec -w /Workspace/Milestone3/ ubuntu_dev_CI ./CreateDailyBuild.sh
docker exec -w /Workspace/Milestone3/Binary ubuntu_dev_CI sh -c "ls -l"
'''
}
}
post {
failure {
echo "Failed during Build Backend stage"
}
}
}
stage ('Deploy Backend3') {
steps {
script {
echo 'Deploy DatabaseGateway and RestApiPortal'
sh '''
docker exec -w /Workspace/Milestone3/Binary ubuntu_dev_CI sh -c "sudo ./DatabaseGateway > database.log &"
sleep 1
docker exec -w /Workspace/Milestone3/Binary ubuntu_dev_CI sh -c "sudo ./RestApiPortal > portal.log &"
sleep 1
docker exec -w /Workspace/Milestone3/ ubuntu_dev_CI ps -ef
'''
}
script {
try {
echo 'Load Database'
sh 'docker exec -w /Workspace/Milestone3/Binary ubuntu_dev_CI sh -c "ls -l"'
sh 'docker exec -w /Workspace/Milestone3/Binary ubuntu_dev_CI sh -c "sudo ./DatabaseTools --PortalIp=127.0.0.1 --Port=6200"'
}catch (exception) {
echo getStackTrace(exception)
echo 'Error detected, retrying...'
sh '''
docker exec -w /Workspace/Milestone3/Binary ubuntu_dev_CI sh -c "sudo ./DatabaseTools --PortalIp=127.0.0.1 --Port=6200 -d"
docker exec -w /Workspace/Milestone3/Binary ubuntu_dev_CI sh -c "sudo ./DatabaseTools --PortalIp=127.0.0.1 --Port=6200"
'''
}
}
echo 'Backend Portal Server is Deployed and Ready to use'
echo 'Build Successful'
sh '''
ps -ef | egrep "DatabaseGateway|RestApiPortal"
killall -9 DatabaseGateway && killall -9 RestApiPortal
'''
}
post {
failure {
echo "Failed during Deploy Backend stage"
}
}
}
stage('Build Backend5') {
steps {
script {
echo 'Build Binaries'
sh label:
'Build Binaries',
script:'''
set -x
docker exec -w /Workspace/Milestone5/ ubuntu_dev_CI ./CreateDailyBuild.sh
docker exec -w /Workspace/Milestone5/Binary ubuntu_dev_CI sh -c "ls -l"
'''
}
}
post {
failure {
echo "Failed during Build Backend stage"
}
}
}
stage ('Deploy Backend5') {
steps {
script {
echo 'Deploy DatabaseGateway and RestApiPortal'
sh '''
docker exec -w /Workspace/Milestone5/Binary ubuntu_dev_CI sh -c "sudo ./DatabaseGateway > database.log &"
sleep 1
docker exec -w /Workspace/Milestone5/Binary ubuntu_dev_CI sh -c "sudo ./RestApiPortal > portal.log &"
sleep 1
docker exec -w /Workspace/Milestone5/ ubuntu_dev_CI ps -ef
'''
}
script {
try {
echo 'Load Database'
sh 'docker exec -w /Workspace/Milestone5/Binary ubuntu_dev_CI sh -c "ls -l"'
sh 'docker exec -w /Workspace/Milestone5/Binary ubuntu_dev_CI sh -c "sudo ./DatabaseTools --PortalIp=127.0.0.1 --Port=6200"'
}catch (exception) {
echo getStackTrace(exception)
echo 'Error detected, retrying...'
sh '''
docker exec -w /Workspace/Milestone5/Binary ubuntu_dev_CI sh -c "sudo ./DatabaseTools --PortalIp=127.0.0.1 --Port=6200 -d"
docker exec -w /Workspace/Milestone5/Binary ubuntu_dev_CI sh -c "sudo ./DatabaseTools --PortalIp=127.0.0.1 --Port=6200"
'''
}
}
echo 'Backend Portal Server is Deployed and Ready to use'
echo 'Build Successful'
sh '''
ps -ef | egrep "DatabaseGateway|RestApiPortal"
killall -9 DatabaseGateway && killall -9 RestApiPortal
'''
}
post {
failure {
echo "Failed during Deploy Backend stage"
}
}
}
}
post {
always {
echo 'Teardown'
sh label:
'Teardown',
script:'''
set -x
docker kill $(docker ps -q)
docker rm $(docker ps -a -q)
'''
}
}
}