-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
106 lines (102 loc) · 3.78 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
101
102
103
104
105
106
#!/usr/bin/env groovy
stage('Set Up') {
milestone()
node {
try {
// delete all untracked files. Use '|| true' in case repo hasn't been checked out previously
sh 'git clean -dfx || true'
echo '************ Getting Repo ************'
checkout scm
echo '************ Installing Composer packages ************'
sh 'composer install'
echo '************ Installing Node modules ************'
sh 'npm set progress=false'
sh 'npm install'
stash 'complete-workspace'
}
catch(error) {
echo "Set up process failed. Deploy halted: ${error.message}"
throw error
}
}
}
stage('Test') {
node {
unstash 'complete-workspace'
echo '************ Testing ************'
try {
sh 'phpunit --log-junit results/phpunit/phpunit.xml -c application/tests'
}
catch(error) {
echo "Tests failed. Deploy halted: ${error.message}"
throw error
}
finally {
junit allowEmptyResults: true, testResults: 'application/tests/results/phpunit/phpunit.xml'
}
}
}
try {
milestone()
stage('Staging') {
try {
lock(resource: 'staging-server', inversePrecedence: true) {
node {
echo ' ************ Deploying to staging server ************'
withCredentials([usernamePassword(credentialsId: 'eddefcd8-350c-4a75-9f2e-bed38fab48c8', passwordVariable: 'FTP_PASSWORD', usernameVariable: 'FTP_USERNAME')]) {
unstash 'complete-workspace'
echo '************ Creating Assets ************'
sh 'npm run build:stage'
sh "./deploy.bash ${env.FTPWPD_HOST} ${FTP_USERNAME} ${FTP_PASSWORD} ${env.CAFPE_DEV_DB} ${env.CAFPE_PROD_DB}"
}
}
milestone()
}
}
catch(error) {
echo "Error: Something went wrong during deployment to staging server"
throw error
}
}
stage('Sanity Check') {
echo ' ************ Decide Release to production server ************'
try {
timeout(time:5, unit:'DAYS') {
input message:'Approve deployment to production?', submitter: 'pablo,pabloguaza'
}
milestone()
}
catch(error) {
echo "Warning: Timeout reached or user aborted production deployment"
throw error
}
}
stage('Production') {
try {
lock(resource: 'production-server', inversePrecedence: true) {
node {
echo ' ************ Release to production server ************'
// TODO: Add deploy command once first migration is made
withCredentials([usernamePassword(credentialsId: '4ef8e4ac-7c5f-4e97-a698-b2ad6909c718', passwordVariable: 'FTP_PASSWORD', usernameVariable: 'FTP_USERNAME')]) {
unstash 'complete-workspace'
// echo '************ Creating Assets ************'
// sh 'npm run build:prod'
}
}
milestone()
}
}
catch(error) {
echo "Error: Something went wrong during deployment to production server"
throw error
}
}
}
catch(error) {
echo "Error: Althought build was SUCCESSFUL, deployment process couldn't be completed: ${error.message}"
}
finally {
// If the script has passed the tests, it has to be marked as successful
// even if deployment stages failed, or execution is aborted
currentBuild.result = "SUCCESS"
}