-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
94 lines (78 loc) · 2.6 KB
/
Jenkinsfile
File metadata and controls
94 lines (78 loc) · 2.6 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
pipeline {
agent any
environment {
IMAGE_NAME = "hunarbaazar-backend"
CONTAINER_NAME = "hunarbaazar"
DOCKERHUB_USER = "khajan_bhatt"
}
stages {
stage('Checkout') {
steps {
git branch: 'master', url: 'https://github.com/group-projects-org/HunarBazaar.git'
}
}
stage('Build Frontend') {
steps {
dir('frontend') {
bat '''
call npm install
call npm run build
'''
}
}
}
stage('Start Docker') {
steps {
powershell '''
$ErrorActionPreference = "SilentlyContinue"
Write-Host "Checking if Docker is running..."
$isRunning = docker info 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ Docker is already running."
exit 0
}
Write-Host "⚙️ Docker not running. Starting Docker Desktop..."
Start-Process "C:\\Program Files\\Docker\\Docker\\Docker Desktop.exe"
Write-Host "⏳ Waiting for Docker daemon to start..."
$maxTries = 20
for ($i = 0; $i -lt $maxTries; $i++) {
docker info 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ Docker is ready!"
exit 0
}
Write-Host "Docker not ready yet ($i/$maxTries)..."
Start-Sleep -Seconds 5
}
Write-Host "❌ Docker did not start in time."
exit 1
'''
}
}
stage('Build Docker Image') {
steps {
bat 'docker build -t %IMAGE_NAME% .'
}
}
stage('Run Unit Tests') {
steps {
withCredentials([
string(credentialsId: 'MONGO_URI', variable: 'MONGO_URI'),
string(credentialsId: 'JWT_SECRET_KEY', variable: 'JWT_SECRET_KEY')
]) {
bat '''
docker run --rm ^
-e MONGO_URI=%MONGO_URI% ^
-e JWT_SECRET_KEY=%JWT_SECRET_KEY% ^
%IMAGE_NAME% sh -c "pytest /app/tests --maxfail=1 --disable-warnings -q"
'''
}
}
}
}
post {
always {
echo "Pipeline completed."
}
}
}