-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
81 lines (73 loc) · 2.97 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
// Define an empty map for storing remote SSH connection parameters
def remote = [:]
pipeline {
agent any
environment {
user = credentials('aclimate_nicaragua_user')
host = credentials('aclimate_nicaragua_host')
name = credentials('aclimate_nicaragua_name')
ssh_key = credentials('aclimate_nicaragua_devops')
}
stages {
stage('Ssh to connect Herschel server') {
steps {
script {
try {
// Set up remote SSH connection parameters
remote.allowAnyHosts = true
remote.identityFile = ssh_key
remote.user = user
remote.name = name
remote.host = host
// Test SSH connection
sshCommand remote: remote, command: "echo 'Connection successful!'"
} catch (Exception e) {
// Capture and handle SSH connection errors
echo "SSH Connection Error: ${e.message}"
error("Failed to establish SSH connection: ${e.message}")
}
}
}
}
stage('Download latest release') {
steps {
script {
try {
sshCommand remote: remote, command: """
cd /var/www/docs/aclimate_nicaragua/
rm -fr aclimate_nicaragua_backup_\$(date +"%Y%m%d")
mkdir aclimate_nicaragua_backup_\$(date +"%Y%m%d")
cp -r /var/www/docs/aclimate_nicaragua/susano/* aclimate_nicaragua_backup_\$(date +"%Y%m%d")
rm -fr react-build.zip
curl -LOk https://github.com/CIAT-DAPA/aclimate_susano/releases/latest/download/react-build.zip
unzip -o react-build.zip
rm -fr react-build.zip
cp -r src/build/* /var/www/docs/aclimate_nicaragua/susano/
rm -fr src
cd /var/www/docs/aclimate_nicaragua/susano/
sudo chown -R scalderon:www-data *
sudo chmod -R 775 *
sudo systemctl reload apache2
"""
} catch (Exception e) {
// Capture and handle errors during the download/deployment stage
echo "Deployment Error: ${e.message}"
error("An error occurred during deployment: ${e.message}")
}
}
}
}
}
post {
failure {
script {
echo "Pipeline failed"
}
}
success {
script {
echo 'Everything went very well!!'
}
}
}
}