-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
204 lines (191 loc) · 5.47 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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
pipeline {
agent any
stages {
stage('SCM') {
steps {
checkout scm
}
}
stage('Setup') {
steps {
script {
sh '''
if ! command -v docker-compose &> /dev/null
then
echo "docker-compose could not be found"
echo "Installing docker-compose"
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
fi
'''
}
}
}
stage('Setup DB') {
steps {
dir('db/'){
sh '''
if [ $(docker ps -a -q -f name=mysql) ]; then
docker stop mysql
docker rm mysql
fi
'''
sh '''
docker-compose up -d
'''
}
}
}
stage('Install MySQL Client') {
steps {
script {
// Run the installation command for default-mysql-client
sh 'apt-get update && apt-get install -y default-mysql-client'
}
}
}
stage('Check MySQL') {
steps {
script {
sh '''
mysqladmin --verbose --wait=30 -hmysql -uroot -proot ping || exit 1
'''
}
}
}
stage('Create DB') {
steps {
script {
sh '''
mysql -hmysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS users_db;"
'''
}
}
}
stage('Migrate DB') {
steps {
dir('code/api'){
sh 'pip3 install -r requirements.txt'
sh 'python3.12 manage.py makemigrations'
sh 'python3.12 manage.py migrate'
}
}
}
stage('E2E Tests') {
when {
anyOf {
branch "main"
branch "testing"
branch "dev-game"
}
}
steps {
script {
sh '''
# Check if Google Chrome is installed
if ! command -v google-chrome-stable &> /dev/null
then
# Install Google Chrome
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/google-chrome.list
apt-get update
apt-get install -y google-chrome-stable
fi
# Check if Chrome WebDriver is installed
if ! command -v /usr/bin/chromedriver &> /dev/null
then
# Download and install Chrome WebDriver
wget "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/120.0.6099.109/linux64/chromedriver-linux64.zip" -O chromedriver_linux64.zip
unzip chromedriver_linux64.zip
mv chromedriver-linux64/chromedriver /usr/bin/chromedriver
chown root:root /usr/bin/chromedriver
chmod +x /usr/bin/chromedriver
fi
# Navigate to the directory containing your E2E tests
cd code/e2e
# Run your E2E tests
pip3 install -r requirements.txt
python3.12 e2etests.py
'''
}
}
}
stage('Build and Test api backend') {
when {
anyOf {
branch "main"
branch "testing"
branch "dev-api"
}
}
steps {
dir('code/api') {
sh 'python3.12 -m coverage run manage.py test'
sh 'python3.12 -m coverage xml -i'
sh '''
if [ -f "coverage.xml" ]; then
echo "coverage.xml file is created."
echo "Path: $(pwd)/coverage.xml"
else
echo "coverage.xml file is not created."
fi
'''
}
}
}
stage('Build and Test game backend') {
when {
anyOf {
branch "main"
branch "testing"
branch "dev-game"
}
}
steps {
dir('code/game/') {
sh 'pip3 install -r requirements.txt'
}
dir('code/game/test/unit') {
sh 'python3.12 -m coverage run -m unittest '
sh 'python3.12 -m coverage xml -i'
sh '''
if [ -f "coverage.xml" ]; then
echo "coverage.xml file is created."
echo "Path: $(pwd)/coverage.xml"
else
echo "coverage.xml file is not created."
fi
'''
}
}
}
stage('Cleanup DB') {
steps {
script {
sh '''
docker stop mysql
docker rm mysql
'''
}
}
}
stage('SonarQube Analysis') {
when {
anyOf {
branch "main"
branch "testing"
}
}
steps {
nodejs(nodeJSInstallationName: 'NodeJS21_1_0') {
script {
def scannerHome = tool 'SonarScanner4'
withSonarQubeEnv("sonarqube") {
sh "${scannerHome}/bin/sonar-scanner -Dsonar.verbose=true"
}
}
}
}
}
}
}