-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
103 lines (97 loc) · 3.89 KB
/
Copy pathJenkinsfile
File metadata and controls
103 lines (97 loc) · 3.89 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
def remote = [:]
pipeline {
agent any
environment {
host = credentials('aclimate_v3_host')
}
stages {
stage('Ssh to connect Melisa server') {
steps {
script {
withCredentials([usernamePassword(credentialsId: 'aclimate_v3_deploy', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
try {
remote.user = USER
remote.password = PASS
remote.host = host
remote.name = host
remote.allowAnyHosts = true
sshCommand remote: remote, command: "echo 'Connection successful!'"
} catch (Exception e) {
echo "SSH Connection Error: ${e.message}"
error("Failed to establish SSH connection: ${e.message}")
}
}
}
}
}
stage('Update API code') {
steps {
script {
try {
sshCommand remote: remote, command: """
cd /var/www/aclimate/aclimate_v3_admin/aclimate_v3_admin
git checkout main
git pull origin main
source /opt/anaconda3/etc/profile.d/conda.sh
conda activate /home/scalderon/.conda/envs/aclimate_v3_admin
pip install -r requirements.txt
"""
} catch (Exception e) {
echo "Git Pull Error: ${e.message}"
error("Failed to update code: ${e.message}")
}
}
}
}
stage('Update Translations') {
steps {
script {
try {
sshCommand remote: remote, command: """
cd /var/www/aclimate/aclimate_v3_admin/aclimate_v3_admin/
source /opt/anaconda3/etc/profile.d/conda.sh
conda activate /home/scalderon/.conda/envs/aclimate_v3_admin
chmod +x update_translations.sh
# Este script SOLO compila .po -> .mo
# NO modifica archivos .po (evita conflictos de merge)
./update_translations.sh
"""
} catch (Exception e) {
echo "Translations error: ${e.message}"
error("Failed to update translations: ${e.message}")
}
}
}
}
stage('Restart API service') {
steps {
script {
try {
sshCommand remote: remote, command: """
cd /var/www/aclimate/aclimate_v3_admin/aclimate_v3_admin/src
source /opt/anaconda3/etc/profile.d/conda.sh
conda activate /home/scalderon/.conda/envs/aclimate_v3_admin
fuser -k 3003/tcp || true
nohup gunicorn -w 4 -b 0.0.0.0:3003 run:app > /var/www/aclimate/aclimate_v3_admin/aclimate_v3_admin/admin.log 2>&1 &
"""
} catch (Exception e) {
echo "API Restart Error: ${e.message}"
error("Failed to restart API: ${e.message}")
}
}
}
}
}
post {
failure {
script {
echo "Pipeline failed"
}
}
success {
script {
echo 'API deployed successfully!'
}
}
}
}