forked from modelon-community/fmi-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.groovy
219 lines (192 loc) · 5.97 KB
/
Jenkinsfile.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
212
213
214
215
216
217
218
// Node requirements:
// VisualStudio2010: C compiler
// OCT-SDK-1.4: CMake, msys
// docker: docker
def Configs = [
'win64': [
name: 'win64',
os: 'windows',
node: 'VisualStudio2010 && OCT-SDK-1.5',
target_install: 'install',
target_test: 'test'
],
'win64_static_runtime': [
name: 'win64_static_runtime',
os: 'windows',
node: 'VisualStudio2010 && OCT-SDK-1.5',
target_install: 'install',
target_test: 'test'
],
'mingw_w64': [
name: 'mingw_w64',
os: 'windows',
node: 'OCT-SDK-1.5',
target_install: 'install',
target_test: 'test'
],
'linux64': [
name: 'linux64',
os: 'linux',
node: 'docker',
target_install: '-C . -f build/docker/Makefile install',
target_test: '-C . -f build/docker/Makefile test'
],
'documentation': [
name: 'documentation',
os: 'linux',
node: 'docker',
target_install: '-C . -f build/docker/Makefile documentation',
target_test: 'N/A'
]
]
def version = '2.0.4-SNAPSHOT' // TODO: seems unused; remove
// Loads the 'signBinaries' function
library 'ModelonCommon@trunk'
def tasks = [:]
// for (conf_entry in Configs) // This doesn't work, causes SerializationError for the Map
Configs.each { conf_entry ->
def conf = conf_entry.value // bind variable before use in closure
tasks[conf.name] = {
node(conf.node) {
def testLogDir = "build-${conf.name}/Testing/Temporary"
def installDir = "install-${conf.name}"
stage("Checkout: ${conf.name}") {
checkout scm
fixFilePermissions(conf.os)
}
stage("Clean artifacts: ${conf.name}") {
clean(conf)
}
stage("Build: ${conf.name}") {
build(conf)
}
stage("Test: ${conf.name}") {
test(conf, testLogDir)
}
stage("Sign: ${conf.name}") {
dir("${installDir}/lib") {
// Seems like .so files are not allowed to be signed,
// so just signing the .dll for now.
signFiles(conf.name, "*.dll")
}
}
stage("Archive: ${conf.name}") {
archiveArtifacts(artifacts: "${installDir}/**")
archiveArtifacts(artifacts: "${testLogDir}/**")
}
}
}
}
def conf = Configs['documentation']
tasks[conf.name] = {
node(conf.node) {
stage("Checkout: ${conf.name}") {
checkout scm
fixFilePermissions(conf.os)
}
stage("Clean artifacts: ${conf.name}") {
clean(conf)
}
stage("Build: ${conf.name}") {
build(conf)
}
stage("Archive: ${conf.name}") {
archiveArtifacts(artifacts: "install-${conf.name}/doc/html/**")
}
}
}
parallel tasks
def clean(conf) {
if (conf.os == 'windows') {
bat """
call build\\setenv.bat
make clean
"""
} else if (conf.os == 'linux') {
sh """
make clean
"""
} else {
error(message: "Invalid configuration operating system: ${conf.os}")
}
}
def build(conf) {
if (conf.os == 'windows') {
bat """
call build\\setenv.bat
make ${conf.target_install} CONFIG_FILE=build/config/${conf.name}
"""
} else if (conf.os == 'linux') {
sh """
make ${conf.target_install} CONFIG_FILE=build/config/${conf.name}
"""
} else {
error(message: "Invalid configuration operating system: ${conf.os}")
}
}
def test(conf, testLogDir) {
def returnStatus
if (conf.os == 'windows') {
returnStatus = bat(returnStatus: true, script: """
call build\\setenv.bat
make ${conf.target_test} CONFIG_FILE=build/config/${conf.name}
""")
} else if (conf.os == 'linux') {
returnStatus = sh(returnStatus: true, script: """
make ${conf.target_test} CONFIG_FILE=build/config/${conf.name}
""")
} else {
error(message: "Invalid config operating system: ${conf.os}")
}
if (returnStatus != 0) {
setBuildStatus('UNSTABLE', "Test failure. Exit code from ctest: ${returnStatus}")
}
dir(testLogDir) {
if (fileExists("LastTestsFailed.log")) {
setBuildStatus('UNSTABLE', "Failing tests: ${testLogDir}/LastTestsFailed.log)")
}
if (!fileExists("LastTest.log")) {
setBuildStatus('UNSTABLE', 'Test log is missing')
}
}
}
/**
* Signs the files that match the glob expressions.
*
* param globExpressions:
* vararg of globExpressions that are evaluated from the current directory
* param prefix:
* used to create a unique intermediate stash (needed for signing),
* and to be displayed in the signBinaries step description
*/
def signFiles(prefix, Object... globExpressions) {
for (glob in globExpressions) {
for (file in findFiles(glob: glob)) {
def fname = file.toString()
def nameUnsigned = "${prefix}_${fname}_unsigned"
def nameSigned = "${prefix}_${fname}_signed"
stash(name: nameUnsigned, includes: file.toString())
signBinaries(nameUnsigned, nameSigned, "Sign binaries: ${fname} (${prefix})")
// Replace the old file with the signed one
deleteFile(fname)
unstash(nameSigned)
}
}
}
def deleteFile(filename) {
bat "del ${filename}"
}
def setBuildStatus(status, msg) {
currentBuild.result = status
println("Build result manually set to ${status}. Reason:\n${msg}")
}
def fixFilePermissions(os) {
if (os == 'linux') {
sh """
# Allow internal docker script to run
chmod a+x build/docker/build.sh
# Allow copying artifacts to host
chmod 777 .
"""
}
}