-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
70 lines (60 loc) · 2.24 KB
/
Jenkinsfile
File metadata and controls
70 lines (60 loc) · 2.24 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
pipeline {
agent any
stages {
stage('Set Environment') {
steps {
script {
echo "Branch Name: ${env.BRANCH_NAME}" // Debugging line
if (env.BRANCH_NAME == 'int') {
env.DEV_SERVER = 'ubuntu@43.205.206.174'
} else if (env.BRANCH_NAME == 'uat') {
env.DEV_SERVER = 'ubuntu@65.0.86.51'
} else if (env.BRANCH_NAME == 'main') {
env.DEV_SERVER = 'ubuntu@3.110.159.100'
} else {
error("Unsupported branch: ${env.BRANCH_NAME}")
}
echo "env.DEV_SERVER: ${env.DEV_SERVER}" // Debugging line
}
}
}
stage('Checkout') {
steps {
echo 'Checkout'
}
}
stage('Test') {
steps {
sh 'python3 -m venv venv'
sh '. venv/bin/activate'
sh 'venv/bin/pip install -r requirements.txt'
echo 'Testing Completed'
}
}
stage('Deploy') {
steps {
sh 'echo "$devServer"'
script {
def deployScript = """
ssh -tt -o StrictHostKeyChecking=no ${env.DEV_SERVER} << EOF
# Kill any process running on port 8000
fuser -k 8000/tcp
# Navigate to the app directory
cd simple-fastapi-app
# Pull the latest code from the respective branch
git pull origin ${env.BRANCH_NAME}
# Activate the virtual environment
source venv/bin/activate
# Start the FastAPI server in the background
nohup uvicorn main:app --host 0.0.0.0 --port 8000 &
exit
EOF
"""
sshagent(['ssh-app-server']) {
sh deployScript
}
}
}
}
}
}