forked from mbeddr/mbeddr.core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmbeddr.groovy
227 lines (200 loc) · 8.08 KB
/
mbeddr.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
219
220
221
222
223
224
225
226
227
#!groovy
def buildMbeddr() {
timestamps {
def gradleOpts ='--no-daemon --info'
def customEnv = setupEnvironment()
def doNotPublish = env.DO_NOT_PUBLISH
withEnv(customEnv) {
stage 'Generate Build Scripts'
sh "./gradlew ${gradleOpts} -b build.gradle build_allScripts --stacktrace --debug"
stage 'Build mbeddr'
sh "./gradlew ${gradleOpts} -b build.gradle build_mbeddr"
stage 'Build Tutorial'
sh "./gradlew ${gradleOpts} -b build.gradle build_tutorial"
stage name: 'Run Tests', concurrency: 2
stash includes: 'MPS/**/*', name: 'mps'
stash includes: 'build/**/*.xml,code/plugins/**/*.xml,code/languages/com.mbeddr.build/solutions/com.mbeddr.rcp/source_gen/com/mbeddr/rcp/config/*,scripts/**/*.xml', name: 'build_scripts'
stash includes: 'artifacts/**/*', name: 'build_mbeddr'
parallel (
//"windows": { runTests('windows')},
"linux": { runTests('linux')}
)
stage 'PackageArtifacts'
//step([$class: 'ArtifactArchiver', artifacts: 'artifacts/', fingerprint: true])
archiveArtifacts artifacts: 'artifacts/', excludes: null, fingerprint: true, onlyIfSuccessful: true
//step([$class: 'ArtifactArchiver', artifacts: 'code/languages/com.mbeddr.build/solutions/com.mbeddr.rcp/source_gen/com/mbeddr/rcp/config/', fingerprint: true])
archiveArtifacts artifacts: 'code/languages/com.mbeddr.build/solutions/com.mbeddr.rcp/source_gen/com/mbeddr/rcp/config/', excludes: null, fingerprint: true, onlyIfSuccessful: true
if((doNotPublish != null) && (!doNotPublish.isEmpty())) {
echo "Skipping stage 'Publish' because property 'DO_NOT_PUBLISH' is set."
} else {
stage 'Publish'
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'mbeddr-ci',
usernameVariable: 'nexusUsername', passwordVariable: 'nexusPassword']])
{
sh "./gradlew ${gradleOpts} -PnexusUsername=${env.nexusUsername} -PnexusPassword=${env.nexusPassword} -b build.gradle publishMbeddrPlatformPublicationToMavenRepository publishMbeddrTutorialPublicationToMavenRepository publishMbeddrAllInOnePublicationToMavenRepository publishMbeddrAllScriptsPublicationToMavenRepository"
}
}
stage 'Cleanup'
deleteDir()
/* Only keep the 25 most recent builds. */
properties([[$class: 'BuildDiscarderProperty',
strategy: [$class: 'LogRotator',
artifactDaysToKeepStr: '',
artifactNumToKeepStr: '10',
daysToKeepStr: '',
numToKeepStr: '25']]]);
}
}
}
def runTests(nodeLabel) {
parallel (
"tests ${nodeLabel} 1" : {
node (nodeLabel) {
runTest("test_mbeddr_core")
runTest("test_mbeddr_ext")
}
},
"tests ${nodeLabel} 2" : {
node (nodeLabel) {
runTest("test_mbeddr_analysis")
runTest("test_mbeddr_tutorial")
}
},
"tests ${nodeLabel} 3" : {
node (nodeLabel) {
runTest("test_mbeddr_platform")
runTest("test_mbeddr_performance")
runTest("test_mbeddr_cc")
}
}
)
}
def getWorkspacePath() {
def ws_path = pwd() + "/"
if(!isUnix()) {
sh 'set'
ws_path = "C:\\ws\\"
}
echo "WS-Path: ${ws_path}"
return ws_path
}
def runTest(gradleTask) {
def gradleOpts ='--no-daemon --info --continue --stacktrace'
def curDir = pwd()
// The tests need an own environment since they can run on different nodes/OS with diffenrent tool paths
def customEnv = setupEnvironment()
customEnv += ["PATH+CBMC_PATH=${curDir}/cbmc"]
withEnv(customEnv) {
//checkout scm
checkoutMbeddr()
try {
if(isUnix()) {
sh "./gradlew ${gradleOpts} -b build.gradle resolve_cbmc"
} else {
bat ".\\gradlew.bat ${gradleOpts} -b build.gradle resolve_cbmc"
}
} catch(err) {
echo "### There were test failures:\n${err}"
}
}
withEnv(customEnv) {
//checkout scm
unstash 'mps'
unstash 'build_scripts'
unstash 'build_mbeddr'
try {
if(isUnix()) {
sh "./gradlew ${gradleOpts} -b build.gradle ${gradleTask}"
} else {
bat ".\\gradlew.bat ${gradleOpts} -b build.gradle ${gradleTask}"
}
step([$class: 'JUnitResultArchiver', testResults: '*/**/TEST-*.xml'])
} catch(err) {
echo "### There were test failures:\n${err}"
}
}
}
// resolve CBMC version from Nexus?
// ->
def initCbmc() {
def curDir = pwd()
echo "CurrDir: $curDir"
stage 'Resolve CBMC'
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'mbeddr-ci',
usernameVariable: 'nexusUsername', passwordVariable: 'nexusPassword']])
{
if(isUnix()) {
sh "./gradlew ${gradleOpts} -PnexusUsername=${env.nexusUsername} -PnexusPassword=${env.nexusPassword} -b build.gradle unzip_cbmcLinux"
//sh "rm -rf ${curDir}/cbmc && mkdir -p ${curDir}/cbmc && cd cbmc/ && tar xvzf ${curDir}/cbmc-linux.tar.gz"
sh "tar xvzf ${curDir}/cbmc-linux.tar.gz"
} else {
sh "./gradlew ${gradleOpts} -PnexusUsername=${env.nexusUsername} -PnexusPassword=${env.nexusPassword} -b build.gradle unzip_cbmcWin"
//bat "del /S /F /Q ${curDir}\\cbmc && mkdir ${curDir}\\cbmc && cd cbmc && unzip ${curDir}\\cbmc-win.zip"
bat "unzip ${curDir}\\cbmc-win.zip"
}
}
/*step ([$class: 'CopyArtifact', projectName: 'Build_CBMC']);
if(isUnix()) {
sh "rm -rf ${curDir}/cbmc && mkdir -p ${curDir}/cbmc && cd cbmc/ && tar xvzf ${curDir}/cbmc-linux.tar.gz"
} else {
bat "del /S /F /Q ${curDir}\\cbmc && mkdir ${curDir}\\cbmc && cd cbmc && unzip ${curDir}\\cbmc-win.zip"
}*/
}
def checkoutMbeddr() {
// Use a local reference git repo to speed up the checkout from GitHub
def reference = env.BSHARE
if(isUnix()) {
reference += "/gitcaches/reference/mbeddr.core/"
} else {
reference = "${BASE}\\workspace\\mbeddr_Reference_Repo\\mbeddr.core\\"
}
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: scm.extensions + [
[$class: 'CloneOption', noTags: false, reference: reference, shallow: false, timeout: 20],
[$class: 'CheckoutOption', timeout: 20],
[$class: 'CleanBeforeCheckout']
],
gitTool: 'Local_Git',
submoduleCfg: [],
userRemoteConfigs: scm.userRemoteConfigs
])
}
def setupEnvironment() {
def javaHome = tool(name: 'JDK 8')
def antHome = tool(name: 'Ant 1.9')
def gradleHome = tool 'Gradle 2.13'
def customEnv = ["PATH+JDK=${javaHome}/bin", "PATH+ANT_HOME=${antHome}/bin", "ANT_HOME=${antHome}", "PATH+GRADLE_HOME=${gradleHome}/bin", "JAVA_HOME=${javaHome}"]
return customEnv
}
/**
* Clean a Git project workspace.
* Uses 'git clean' if there is a repository found.
* Uses Pipeline 'deleteDir()' function if no .git directory is found.
*/
def gitClean() {
timeout(time: 60, unit: 'SECONDS') {
if (fileExists('.git')) {
echo 'Found Git repository: using Git to clean the tree.'
// The sequence of reset --hard and clean -fdx first
// in the root and then using submodule foreach
// is based on how the Jenkins Git SCM clean before checkout
// feature works.
sh 'git reset --hard'
// Note: -e is necessary to exclude the temp directory
// .jenkins-XXXXX in the workspace where Pipeline puts the
// batch file for the 'bat' command.
sh 'git clean -ffdx -e ".jenkins-*/"'
sh 'git submodule foreach --recursive git reset --hard'
sh 'git submodule foreach --recursive git clean -ffdx'
}
else
{
echo 'No Git repository found: using deleteDir() to wipe clean'
deleteDir()
}
}
}
return this;