-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
100 lines (87 loc) · 3.18 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
97
98
99
100
// Define an empty map for storing remote SSH connection parameters
def remote = [:]
pipeline {
agent any
environment {
server_name = credentials('wp_name')
server_host = credentials('wp_host')
ssh_key = credentials('wp_devops')
api_wp_url=credentials('api_wp_url')
key_graphhopper=credentials('key_graphhopper')
}
stages {
stage('Connection to AWS server') {
steps {
script {
// Set up remote SSH connection parameterss
remote.allowAnyHosts = true
remote.identityFile = ssh_key
remote.user = ssh_key_USR
remote.name = server_name
remote.host = server_host
}
}
}
stage('Verify webapp folder and environment') {
steps {
script {
sshCommand remote: remote, command: '''
# Verify and create the wepapp_folder folder if it does not exist
cd /var/www/waterpointsFrontend
if [ ! -d webapp_WP ]; then
mkdir ./webapp_WP
cd ./webapp_WP
fi
'''
}
}
}
stage('Download latest release') {
steps {
script {
sshCommand remote: remote, command: '''
# Download the latest release f1081419031Nasa@rom GitHub
cd /var/www/waterpointsFrontend
cd ./webapp_WP
rm -rf build
curl -LOk https://github.com/CIAT-DAPA/lswms_website/releases/latest/download/releaseFront.zip
unzip releaseFront.zip -d build
rm -r releaseFront.zip
'''
}
}
}
stage('Verify and control PM2 service') {
steps {
script {
sshCommand remote: remote, command: '''
# Verify and control PM2 service
cd /var/www/waterpointsFrontend
cd ./webapp_WP
if pm2 show waterpointsfrontend >/dev/null 2>&1; then
echo "stopping PM2 process..."
pm2 stop waterpointsfrontend
fi
echo "starting PM2 process..."
export REACT_APP_PRODUCTION_API_URL=${api_wp_url}
export REACT_APP_KEY_GRAPHHOPER=${key_graphhopper}
export REACT_APP_DEBUG=false
pm2 serve build 5000 --name waterpointsfrontend --spa
'''
}
}
}
}
post {
failure {
script {
echo 'fail :c'
}
}
success {
script {
echo 'everything went very well!!'
}
}
}
}