forked from CISC375/Sage
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
169 lines (167 loc) · 5.08 KB
/
Jenkinsfile
File metadata and controls
169 lines (167 loc) · 5.08 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
def boolean stage_results = false
pipeline {
agent any
environment {
DISCORD_WEBHOOK=credentials('3fbb794c-1c40-4471-9eee-d147d4506046')
MAIN_BRANCH='main'
SAGE_DIR='/usr/local/sage/SageV2'
JENKINS_NODE_COOKIE='dontKillMe'
}
stages {
stage('Test Build') {
steps {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
sh 'find /tmp -user jenkins -print0 | xargs -0 rm -rf'
sh 'echo "running build in temp workspace"'
sh 'mv config.example.ts config.ts'
sh 'npm run clean'
sh 'npm cache clean --force'
sh 'rm -rf node_modules'
sh 'npm i'
sh 'npm run build'
script{ stage_results = true }
}
script {
discordSend(
description: "Test build " + currentBuild.currentResult + " on branch [" + env.BRANCH_NAME +
"](https://github.com/ud-cis-discord/SageV2/commit/" + env.GIT_COMMIT + ")",
footer: env.BUILD_TAG,
link: env.BUILD_URL,
result: currentBuild.currentResult,
title: JOB_NAME + " -- Test Build",
webhookURL: env.DISCORD_WEBHOOK
)
if (stage_results == false) {
sh 'exit 1'
}
stage_results = false
}
}
}
stage('Lint') {
steps {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
sh 'echo "testing in temp workspace..."'
sh 'npm run test'
script{ stage_results = true }
}
script {
discordSend(
description: "Lint " + currentBuild.currentResult + " on branch [" + env.BRANCH_NAME +
"](https://github.com/ud-cis-discord/SageV2/commit/" + env.GIT_COMMIT + ")",
footer: env.BUILD_TAG,
link: env.BUILD_URL,
result: currentBuild.currentResult,
title: JOB_NAME + " -- Lint",
webhookURL: env.DISCORD_WEBHOOK
)
if (stage_results == false) {
sh 'exit 1'
}
stage_results = false
}
}
}
stage('Integration Tests') {
steps {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
sh 'echo "running integration tests..."'
sh 'npm run test:integration'
script{ stage_results = true }
}
script {
discordSend(
description: "Integration tests " + currentBuild.currentResult + " on branch [" + env.BRANCH_NAME +
"](https://github.com/ud-cis-discord/SageV2/commit/" + env.GIT_COMMIT + ")",
footer: env.BUILD_TAG,
link: env.BUILD_URL,
result: currentBuild.currentResult,
title: JOB_NAME + " -- Integration Tests",
webhookURL: env.DISCORD_WEBHOOK
)
if (stage_results == false) {
sh 'exit 1'
}
stage_results = false
}
}
}
stage('Deploy') {
steps {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
script {
if(env.BRANCH_NAME == env.MAIN_BRANCH) {
sh 'echo "rebuilding and deploying in prod directory..."'
sh 'cd ' + env.SAGE_DIR + ' && git pull && npm run clean && npm i && npm run build && sudo /bin/systemctl restart sage'
} else {
echo 'build done, branch OK'
}
stage_results = true
}
}
script {
def discord_desc = "Deploy " + currentBuild.currentResult + " on branch [" + env.BRANCH_NAME + "](https://github.com/ud-cis-discord/SageV2/commit/" + env.GIT_COMMIT + ")"
if(stage_results == false && env.BRANCH_NAME == env.MAIN_BRANCH) {
discord_desc = "URGENT!! -- " + discord_desc
}
if(env.BRANCH_NAME == env.MAIN_BRANCH) {
discordSend(
description: discord_desc,
footer: env.BUILD_TAG,
link: env.BUILD_URL,
result: currentBuild.currentResult,
title: JOB_NAME + " -- Deploy",
webhookURL: env.DISCORD_WEBHOOK
)}
if (stage_results == false) {
sh 'exit 1'
}
}
}
}
stage('Update Docs') {
steps {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
script {
if(env.BRANCH_NAME == env.MAIN_BRANCH) {
sh 'echo "automatically updating the documentation website"'
sh 'cd ' + env.SAGE_DIR + ' && npm run autodoc'
}
stage_results = true
}
}
script {
def discord_desc = "doc automation" + currentBuild.currentResult + " on branch [" + env.BRANCH_NAME + "](https://github.com/ud-cis-discord/SageV2/commit/" + env.GIT_COMMIT + ")"
if(stage_results == false && env.BRANCH_NAME == env.MAIN_BRANCH) {
discord_desc = "URGENT!! -- " + discord_desc
}
if(env.BRANCH_NAME == env.MAIN_BRANCH) {
discordSend(
description: discord_desc,
footer: env.BUILD_TAG,
link: env.BUILD_URL,
result: currentBuild.currentResult,
title: JOB_NAME + " -- Documentation Update",
webhookURL: env.DISCORD_WEBHOOK
)}
if (stage_results == false) {
sh 'exit 1'
}
}
}
}
}
post {
always {
discordSend(
description: "Pipeline " + currentBuild.currentResult + " on branch [" + env.BRANCH_NAME +
"](https://github.com/ud-cis-discord/SageV2/commit/" + env.GIT_COMMIT + ")",
footer: env.BUILD_TAG,
link: env.BUILD_URL,
result: currentBuild.currentResult,
title: JOB_NAME,
webhookURL: env.DISCORD_WEBHOOK
)
}
}
}