-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile
98 lines (94 loc) · 3.71 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
pipeline {
agent {
docker { image 'node:20.11-alpine' }
}
environment {
WSO_REACT_DISCORD_WEBHOOK_URL = credentials('WSO_REACT_DISCORD_WEBHOOK_URL')
}
stages {
stage('Deploy for development') {
when {
branch 'master'
}
steps {
sh '''yarn install --frozen-lockfile'''
sh '''yarn run build'''
script {
def remote_dev = [:]
remote_dev.name = "wsodev"
remote_dev.host = "wso-dev.williams.edu"
remote_dev.port = 22
remote_dev.allowAnyHosts = true
withCredentials([usernamePassword(credentialsId: 'wsodev_ssh_server', passwordVariable: 'SSH_PASS', usernameVariable: 'SSH_USER')]) {
remote_dev.user = SSH_USER
remote_dev.password = SSH_PASS
sshRemove remote: remote_dev, path: '/home/wsodev/wso-react/build'
sshPut remote: remote_dev, from: 'build', into: '/home/wsodev/wso-react/'
}
}
script {
try {
new URL("https://wso-dev.williams.edu").getText()
return true
} catch (Exception e) {
return false
}
}
}
post {
success {
slackSend (color: '#00FF00', message: "WSO-React Deployed on Development\n Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
discordSend (title: "WSO-React Deployed on Development", description: "Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})", link: env.BUILD_URL, result: currentBuild.currentResult, webhookURL: "${env.WSO_REACT_DISCORD_WEBHOOK_URL}")
}
failure {
discordSend (title: "WSO-React Fail to Deploy on Development", description: "Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})", link: env.BUILD_URL, result: currentBuild.currentResult, webhookURL: "${env.WSO_REACT_DISCORD_WEBHOOK_URL}")
}
}
}
stage('Deploy for production') {
when {
branch 'production'
}
steps {
sh '''yarn install --frozen-lockfile'''
sh '''yarn run build'''
script {
def remote_dev = [:]
remote_dev.name = "wso"
remote_dev.host = "wso.williams.edu"
remote_dev.port = 22
remote_dev.allowAnyHosts = true
withCredentials([usernamePassword(credentialsId: 'wso_ssh_server', passwordVariable: 'SSH_PASS', usernameVariable: 'SSH_USER')]) {
remote_dev.user = SSH_USER
remote_dev.password = SSH_PASS
sshRemove remote: remote_dev, path: '/home/wso/wso/wso-react/build'
sshPut remote: remote_dev, from: 'build', into: '/home/wso/wso/wso-react/'
}
}
script {
try {
new URL("https://wso.williams.edu").getText()
return true
} catch (Exception e) {
return false
}
}
}
post {
success {
slackSend (color: '#00FF00', message: "WSO-React Deployed on Production\n Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
discordSend (title: "WSO-React Deployed on Production", description: "Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})", link: env.BUILD_URL, result: currentBuild.currentResult, webhookURL: "${env.WSO_REACT_DISCORD_WEBHOOK_URL}")
}
failure {
discordSend (title: "WSO-React Failed to Deploy on Production", description: "Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})", link: env.BUILD_URL, result: currentBuild.currentResult, webhookURL: "${env.WSO_REACT_DISCORD_WEBHOOK_URL}")
}
}
}
}
options { buildDiscarder(logRotator(numToKeepStr: '2')) }
post {
cleanup {
cleanWs()
}
}
}