This repository has been archived by the owner on Mar 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile.json
88 lines (70 loc) · 2.28 KB
/
Jenkinsfile.json
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
#!/usr/bin/env groovy
node {
try {
notifyStarted()
echo 'Job name : ' + env.JOB_NAME
stage('Checkout') {
checkout scm
}
String appDirectory = 'bioexcel-app-dev'
String environment = 'DEV'
if(env.JOB_NAME.endsWith("bioexcel-app")){
environment = 'PROD'
appDirectory = 'bioexcel-app'
}
echo 'Build Environment : ' + environment
// Artifact name
String archiveName = "${appDirectory}.tgz"
withNodeEnv {
stage('Build') {
sh 'npm install'
if(environment == 'PROD'){
sh 'ng build --env=prod --progress=false'
}else{
sh 'ng build --progress=false'
}
}
}
stage('Archive') {
sh "touch dist/${archiveName}"
sh "tar -czf dist/${archiveName} --exclude=${archiveName} -C dist/ ."
archiveArtifacts artifacts: "**/dist/${archiveName}", fingerprint: true
}
stage('Deploy') {
server = '[email protected]'
webRoot = "/usr/share/nginx/${appDirectory}/"
sshagent(credentials: ['ssh-deploy']) {
sh "ssh -tt ${server} 'sudo rm -rf ${webRoot}*'"
sh "scp dist/${archiveName} ${server}:~"
sh "ssh -tt ${server} 'sudo tar -xzf ${archiveName} -C ${webRoot}'"
sh "ssh -tt ${server} 'sudo chown root.root -R ${webRoot}*'"
}
}
stage('Cleanup') {
sh 'rm -rf dist'
}
notifySuccessful()
} catch (e) {
currentBuild.result = "FAILED"
notifyFailed()
throw e
}
}
void withNodeEnv(Closure body) {
String nodeTool = tool name: 'ecp-cloud-portal-app', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
// Create environment with NodeJS added to the PATH.
List nodeEnv = ["PATH+NODE=${nodeTool}/bin", "PATH+NODE_MODULES=./node_modules/.bin"]
// Invoke the body closure within in the environment with NodeJS added.
withEnv(nodeEnv) {
body.call()
}
}
def notifyStarted() {
slackSend (color: '#FFFF00', message: "STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
def notifySuccessful() {
slackSend (color: '#00FF00', message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
def notifyFailed() {
slackSend (color: '#FF0000', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}