-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
96 lines (96 loc) · 2.77 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
pipeline {
agent {
node {
label 'docker-python'
}
}
//agent any // Use any available agent
stages {
stage ('Setup')
{
steps {
script {
// Set default branch to main, if it's not set
env.BRANCH_NAME = "${GIT_BRANCH.split("/")[1]}"
}
}
}
stage('Build') {
steps {
echo "Building... for branch ${env.BRANCH_NAME}"
// Install dependencies
sh '''
cd app/backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
'''
}
}
stage('Test') {
steps {
echo "Testing... for branch ${env.BRANCH_NAME}"
// Run tests
sh '''
cd app/backend
source venv/bin/activate
python3 -m unittest discover
'''
}
}
stage('Deploy - Mock')
{
// Mock Deployment for non-dev branches (for testing purposes)
when {
expression {
return env.BRANCH_NAME != 'dev'
}
}
steps {
echo "Deploying... for branch ${env.BRANCH_NAME}"
// Deploy to mock environment
sh '''
cd app/backend
source venv/bin/activate
echo "Deploying to mock environment"
'''
}
}
stage('Deploy - Production')
{
// Deploy to production for dev branche
when {
expression {
return env.BRANCH_NAME == 'dev'
}
}
steps {
sshagent (['JK']) {
echo "Deploying... for branch ${env.BRANCH_NAME}"
// Deploy to production environment
// API hosted on Render, merge dev to main will automatically deploy to production
sh '''
git config --global user.name "Jenkins CI"
git config --global user.email "[email protected]"
git checkout main
git pull origin main
git merge origin/dev
git push origin main
'''
}
}
}
}
post
{
success {
echo 'Build and deployment successful!'
}
failure {
echo 'Build failed, check Jenkins logs.'
}
aborted {
echo 'Build aborted!'
}
}
}