forked from DOI-USGS/ISIS3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.groovy
211 lines (182 loc) · 6.59 KB
/
build.groovy
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// vim: ft=groovy
def condaPath = ""
def isisEnv = [
"ISIS3DATA=/isisData/data",
"ISIS3TESTDATA=/isisData/testData",
"ISIS3MGRSCRIPTS=/isisData/data/isis3mgr_scripts",
]
def cmakeFlags = [
"-DJP2KFLAG=ON",
"-DKAKADU_INCLUDE_DIR=/isisData/kakadu",
"-Dpybindings=OFF",
"-DCMAKE_BUILD_TYPE=RELEASE"
]
def build_ok = true
def errors = []
// Helpers for setting commit status
def getRepoUrl() {
return sh(script: "git config --get remote.origin.url", returnStdout: true).trim()
}
def getCommitSha() {
return sh(script: "git rev-parse HEAD", returnStdout: true).trim()
}
def setGitHubBuildStatus(status) {
def repoUrl = getRepoUrl()
def commitSha = getCommitSha()
step([
$class: 'GitHubCommitStatusSetter',
reposSource: [$class: "ManuallyEnteredRepositorySource", url: repoUrl],
commitShaSource: [$class: "ManuallyEnteredShaSource", sha: commitSha],
errorHandlers: [[$class: 'ShallowAnyErrorHandler']],
statusResultSource: [
$class: 'ConditionalStatusResultSource',
results: [
[$class: 'BetterThanOrEqualBuildResult', result: 'SUCCESS', state: 'SUCCESS', message: status],
[$class: 'BetterThanOrEqualBuildResult', result: 'FAILURE', state: 'FAILURE', message: status],
[$class: 'AnyBuildResult', state: 'FAILURE', message: 'Loophole']
]
]
])
}
node("${env.OS.toLowerCase()}") {
stage ("Checkout") {
env.STAGE_STATUS = "Checking out ISIS"
sh 'git config --global http.sslVerify false'
checkout scm
isisEnv.add("ISISROOT=${pwd()}/build")
cmakeFlags.add("-DCMAKE_INSTALL_PREFIX=${pwd()}/install")
}
stage("Create environment") {
env.STAGE_STATUS = "Creating conda environment"
if (env.OS.toLowerCase() == "mac") {
condaPath = "/tmp/" + sh(script: '{ date "+%m/%d/%y|%H:%M:%S:%m"; echo $WORKSPACE; } | md5 | tr -d "\n";', returnStdout: true)
sh """
curl -o miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
bash miniconda.sh -b -p ${condaPath}
"""
} else {
condaPath = "/home/jenkins/.conda/"
}
isisEnv.add("PATH=${pwd()}/install/bin:$condaPath/envs/isis/bin:$condaPath/bin:${env.PATH}")
withEnv(isisEnv) {
println("Complete Environment:")
sh 'printenv'
println("Anaconda Path: " + condaPath)
sh """
# Use the conda cache running on the Jenkins host
# conda config --set channel_alias http://dmz-jenkins.wr.usgs.gov
conda config --set always_yes True
conda config --set ssl_verify false
conda update -n base -c defaults conda
"""
if (env.OS.toLowerCase() == "centos") {
sh 'conda env create -n isis -f environment_gcc4.yml'
} else {
sh """
conda config --show channels
conda env create -n isis -f environment.yml
"""
}
}
}
withEnv(isisEnv) {
dir("${env.ISISROOT}") {
try {
stage ("Build") {
env.STAGE_STATUS = "Building ISIS on ${env.OS}"
sh """
source activate ${condaPath}/envs/isis
echo `ls ../`
echo `pwd`
conda list
cmake -GNinja ${cmakeFlags.join(' ')} ../isis
ninja -j4 install
"""
}
}
catch(e) {
build_ok = false
errors.add(env.STAGE_STATUS)
println e.toString()
}
if (build_ok) {
try{
stage("UnitTests") {
dir("${env.ISISROOT}") {
env.STAGE_STATUS = "Running unit tests on ${env.OS}"
sh """
source activate ${condaPath}/envs/isis
ctest -R _unit_ -j4 -VV
"""
}
}
}
catch(e) {
build_ok = false
echo e.toString()
}
sh 'source deactivate'
try{
stage("AppTests") {
env.STAGE_STATUS = "Running app tests on ${env.OS}"
sh """
source activate ${condaPath}/envs/isis
echo $PATH
ctest -R _app_ -j4 -VV
"""
}
}
catch(e) {
build_ok = false
errors.add(env.STAGE_STATUS)
println e.toString()
}
sh 'source deactivate'
try{
stage("ModuleTests") {
env.STAGE_STATUS = "Running module tests on ${env.OS}"
sh """
source activate ${condaPath}/envs/isis
ctest -R _module_ -j4 -VV
"""
}
}
catch(e) {
build_ok = false
errors.add(env.STAGE_STATUS)
println e.toString()
}
sh 'source deactivate'
try{
stage("GTests") {
env.STAGE_STATUS = "Running gtests on ${env.OS}"
sh """
source activate ${condaPath}/envs/isis
ctest -R "." -E "(_app_|_unit_|_module_)" -j4 -VV
"""
}
}
catch(e) {
build_ok = false
errors.add(env.STAGE_STATUS)
println e.toString()
}
sh 'source deactivate'
}
}
if(build_ok) {
currentBuild.result = "SUCCESS"
}
else {
currentBuild.result = "FAILURE"
def comment = "Failed during:\n"
errors.each {
comment += "- ${it}\n"
}
setGitHubBuildStatus(comment)
}
}
stage("Clean Up") {
env.STAGE_STATUS = "Removing conda environment"
}
}