-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
170 lines (158 loc) · 5.56 KB
/
Jenkinsfile
File metadata and controls
170 lines (158 loc) · 5.56 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
170
/*
There are three scenarios the pipeline runs against;
1) The target branch is master and current branch is lang/framework; linting, src code testing & api testing should be run
2) The target branch is lang/framework; linting & src code testing should be run
3) The target branch is neither of the above; no steps should be run
*/
// Append new lang/framework branch names when ready for pipeline builds
def langFrameworks = [
"csharp/aspnet",
"go/mux",
"js/express",
"ruby/sinatra"
]
def isIntoMaster = false
def isIntoLangFramework = false
def buildPath = ""
def buildService = ""
def apiTestPath = ""
if (env.CHANGE_TARGET == "master" && langFrameworks.contains(env.CHANGE_BRANCH)) {
isIntoMaster = true
buildPath = "${env.CHANGE_BRANCH}"
buildService = buildPath.replace('/', '_')
apiTestPath = "api_testing"
} else if (langFrameworks.contains(env.CHANGE_TARGET)) {
isIntoLangFramework = true
buildPath = "${env.CHANGE_TARGET}"
}
def formatMessage(msg) {
"```\n${msg.substring(0, Math.min(255, msg.length()))}\n```"
}
pipeline {
agent any
stages {
stage("Build") {
when {
expression {
return isIntoMaster || isIntoLangFramework
}
}
steps {
script {
try {
dir(buildPath) {
sh "chmod 700 -R ./scripts"
sh "find . -name \"*.json\" -exec chmod 600 {} \\;"
}
echo "Running build script; ./scripts/build.sh ${buildPath}"
sh "chmod 700 -R ./scripts"
sh "./scripts/build.sh ${buildPath}"
} catch (e) {
pullRequest.comment("BUILD FAILED ❌. SEE ERROR MESSAGE BELOW:\n${formatMessage(e.message)}")
throw e
}
}
}
}
stage("Linting") {
when {
expression {
return isIntoMaster || isIntoLangFramework
}
}
steps {
script {
try {
echo "Running lint script; ./scripts/run.sh ${buildPath} lint"
sh "./scripts/run.sh ${buildPath} lint"
} catch (e) {
pullRequest.comment("LINTING FAILED ❌. SEE ERROR MESSAGE BELOW:\n${formatMessage(e.message)}")
throw e
}
}
}
}
stage("Src Testing") {
when {
expression {
return isIntoMaster || isIntoLangFramework
}
}
steps {
script {
try {
echo "Running src test script; ./scripts/run.sh ${buildPath} test"
sh "./scripts/run.sh ${buildPath} test"
} catch (e) {
pullRequest.comment("SRC TESTING FAILED ❌. SEE ERROR MESSAGE BELOW:\n${formatMessage(e.message)}")
throw e
}
}
}
}
stage("Health Check") {
when {
expression {
return isIntoMaster || isIntoLangFramework
}
}
steps {
script {
try {
echo "Running api script; ./scripts/run.sh ${buildPath}"
sh "./scripts/run.sh ${buildPath}"
sh "./scripts/health_check.sh"
} catch (e) {
pullRequest.comment("HEALTH CHECK FAILED ❌. SEE ERROR MESSAGE BELOW:\n${formatMessage(e.message)}")
throw e
}
}
}
}
stage("API Testing") {
when {
expression {
return isIntoMaster
}
}
steps {
script {
try {
echo "Running expectations api build script; ${apiTestPath}/expectations_api/scripts/build_img.sh"
dir("${apiTestPath}/expectations_api") {
sh "chmod 700 -R ./scripts"
sh "./scripts/build_img.sh"
echo "Running expectations api script; ${apiTestPath}/expectations_api/scripts/run_img.sh"
sh "./scripts/run_img.sh"
}
echo "Running api tests!"
dir(apiTestPath) {
sh "chmod 700 ./run.sh"
sh "./run.sh ${buildService}"
}
} catch (e) {
pullRequest.comment("API TESTS FAILED ❌. SEE ERROR MESSAGE BELOW:\n${formatMessage(e.message)}")
throw e
}
}
}
}
stage("Finish") {
steps {
script {
pullRequest.comment("BUILD SUCCESSFUL ✔️")
}
}
}
}
post {
always {
script {
if (isIntoMaster || isIntoLangFramework) {
echo "Running clean up script; ./scripts/clean.sh ${buildPath}"
sh "./scripts/clean.sh ${buildPath}"
}
}
}
}
}