forked from apache/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
296 lines (262 loc) · 10.2 KB
/
Jenkinsfile
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#!groovytestReport
def testReport = "TestReport.xml"
def cases = []
def commitid = ""
def cronSettings = "0 0 0 * *"
def ciWorkSpace = ""
if(BRANCH_NAME == "nuttx_with_hpmsdk"){
cronSettings = "0 12 * * *" // default set 12 clock to execute every day
} else {
cronSettings = "0 0 31 2 *"
}
class Globals {
static linuxReportStash = [:] //buildnode: stashreport
static String buildCodeClone = "git clone git@192.168.11.211:swtesting/ci_build.git -b release_3.1.0"
static String nuttxCodeClone = "git@192.168.11.211:oss/nuttx.git"
static String appsCodeClone = "git clone git@192.168.11.211:oss/nuttx_apps.git apps -b nuttx_apps_v12.4"
// static String appsPackage = "nuttx-apps-nuttx-12.4.*"
static String appsPatch = "/home/builder/build/workspace/nuttx_apps.patch"
}
pipeline {
agent {
label "linux_node"
}
options {
skipDefaultCheckout()
buildDiscarder(logRotator(numToKeepStr: '15', artifactNumToKeepStr: '15'))
timestamps()
}
triggers {
cron(cronSettings)
}
stages {
stage("Checkout repo"){
when {
branch BRANCH_NAME
}
steps {
println "BRANCH_NAME:$BRANCH_NAME"
println WORKSPACE
deleteDir()
// checkout scm
script {
sh("$Globals.buildCodeClone && git clone $Globals.nuttxCodeClone -b $BRANCH_NAME")
commitid = sh(returnStdout: true, script: "cd nuttx && git rev-parse --short HEAD").trim()
}
}
}
stage("collect case list"){
when {
branch BRANCH_NAME
}
steps {
script {
sh("export PATH=$PATH:/home/builder/nuttx_toolchain/riscv32-unknown-elf-newlib-multilib/bin && cd ci_build && /home/builder/.local/bin/pytest --collect-only --jenkins_project nuttx --project_src_dir ${WORKSPACE}/nuttx --build_dir ${WORKSPACE}/output test_build/test_nuttx_build/test_build.py")
def caseFile = "$WORKSPACE/ci_build/caselist.csv"
if(fileExists(caseFile)) {
echo 'caselist.csv found'
readFile(caseFile).split('\n').each { line, count ->
cases.add(line.split(',')[1])
}
cases = cases[1..-1] // ignore header column
}
}
}
}
stage("parallel_build"){
when {
branch BRANCH_NAME
}
steps{
script {
def projectName = getProjectName()
def buildStages = [:]
if(projectName.indexOf("nuttx") != -1){
buildStages = getParallelStageByCaseBalance(cases, "linux")
}
parallel buildStages
}
}
}
stage("merge report"){
when {
branch BRANCH_NAME
}
steps {
script {
ciWorkSpace = "$WORKSPACE/ci_build"
// unstash report for each build
def merge_cmd = "/home/builder/.local/bin/junitparser merge"
Globals.linuxReportStash.each{node, report ->
unstash name: report
merge_cmd = merge_cmd + " " + "ci_build/${report}.xml"
}
merge_cmd = merge_cmd + " " + testReport
sh(merge_cmd)
junit testReport
}
archiveArtifacts artifacts: testReport, fingerprint: true
}
}
}
post {
always {
echo "Done with the Build"
script {
def changeSets = getChangeSets().toString()
gen_report_cmd = "python3 ci_build/nuttx_generate_report.py --xml_reportfile $testReport --build_url ${BUILD_URL} --build_date \"${BUILD_TIMESTAMP}\" --build_duration \"${currentBuild.durationString}\" --git_commit $commitid --branch ${BRANCH_NAME} --cause \"${currentBuild.getBuildCauses()[0].shortDescription}\" --changesets \"${changeSets}\""
sh(gen_report_cmd)
}
//archiveArtifacts artifacts: "*.zip", fingerprint: true
//cleanWs()
}// always
success {
script {
println "****Success****"
testResult = "success"
EmailNotification(commitid, testResult)
}// script
}// success
failure {
script {
println "****Failure****"
testResult = "failure"
EmailNotification(commitid, testResult)
}// script
}// failure
unstable {
script {
println "****Unstable****"
testResult = "unstable"
EmailNotification(commitid, testResult)
}// script
}// unstable
}// post
}// pipeline
@NonCPS
List <String> getOnlineNodeNames(filterLabel) {
List <String> nodeNames = []
def allNodes = Jenkins.getInstance().getNodes()
for (int i =0; i < allNodes.size(); i++) {
Slave node = allNodes[i]
if (node.getComputer().isOnline() && node.getLabelString().matches(filterLabel + "(.*)")){
nodeNames.add(node.getLabelString())
}
}
return nodeNames
}
@NonCPS
def getChangeSets(){
def changeSets = []
def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def changeStr = ""
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
changeStr = "'${entry.commitId[0..6]} revision by ${entry.author}: ${entry.msg}'"
changeSets.add(changeStr)
}
}
return changeSets
}
String getBranchName(){
def branchName = "${BRANCH_NAME}"
return branchName
}
String getProjectName(){
def projectName = "${JOB_NAME}"
println "Job Name:${projectName}"
projectName = projectName.split("/")[0]
return projectName
}
def getParallelStageByCaseBalance(cases, os){
def buildNodes = []
def branchName = getBranchName()
def projectName = getProjectName()
if(os == "linux"){
buildNodes = getOnlineNodeNames("Linux_build")
// buildNodes = getOnlineNodeNames("qa_builder")
println "buildNodes: ${buildNodes}"
} else {
buildNodes = getOnlineNodeNames("Windows_build")
}
def nodeCaseMap = [:]
def nodeIndex = 0
// Init nodeCaseMap
for(node in buildNodes){
nodeCaseMap[node] = []
}
// each node add case
for(caseName in cases){
if(nodeIndex == buildNodes.size()){
nodeIndex = 0
}
nodeCaseMap[buildNodes[nodeIndex]].add(caseName)
nodeIndex = nodeIndex + 1
}
println "nodeCaseMap: ${nodeCaseMap}"
// nodeCaseMap = ["qa_builder":["test_build.py::test_build[hpm6750evk2-sdk_gpio-ram_debug]", "test_build.py::test_build[hpm6750evk2-sdk_gpio-flash_xip]"]]
def buildStages = [:]
nodeCaseMap.each { buildNode, runCases ->
buildStages[buildNode + "_build"] = {
node(buildNode){
stage(buildNode + "_build"){
deleteDir()
if(os == "linux"){
String casesStr = ""
if(runCases.size() != 0){
for(String caseName in runCases){
casesStr = casesStr + " " + caseName[0..-1]
}
def outputPath = "$WORKSPACE/$BUILD_ID/output"
def buildPath = "$WORKSPACE/ci_build"
def nuttxPath = "$WORKSPACE/nuttx"
sh("$Globals.appsCodeClone && cd apps && git apply $Globals.appsPatch")
sh("$Globals.buildCodeClone && git clone $Globals.nuttxCodeClone -b $branchName")
sh("export PATH=$PATH:/home/builder/nuttx_toolchain/riscv32-unknown-elf-newlib-multilib/bin && cd $buildPath/test_build/test_nuttx_build && /home/builder/.local/bin/pytest --suppress-tests-failed-exit-code --jenkins_project $projectName $casesStr --project_src_dir $nuttxPath --build_dir $outputPath --junit-xml=$buildPath/report_${buildNode}.xml --jenkins_build_id $BUILD_ID --jenkins_branch $BRANCH_NAME -p no:warnings")
stash includes: "ci_build/report_${buildNode}.xml", name:"report_${buildNode}"
Globals.linuxReportStash.put(buildNode, "report_${buildNode}")
} else {
println "No case assigned"
}
}
}
}
}
}
return buildStages
}
def EmailNotification(commitid, buildResult){
def os = ""
def project = scm.getUserRemoteConfigs()[0].getUrl().tokenize('/').last().split("\\.")[0]
println "${currentBuild.getBuildCauses()[0].shortDescription}"
def jenkinsBuildType = "Daily Build"
if(currentBuild.getBuildCauses()[0].shortDescription == 'Started by timer'){
jenkinsBuildType = "Daily Build"
}
if(getProjectName().indexOf("nuttx") != -1){
os = "Linux"
} else {
os = "Windows"
}
def mailList = ""
def jobName = currentBuild.fullDisplayName
def testResult = "Passed"
if(buildResult == "success"){
mailList = "sw@hpmicro.com"
testResult = "Passed"
} else if(buildResult == "failure"){
mailList = "swtest@hpmicro.com"
testResult = "Failed"
} else {
mailList = "sw@hpmicro.com"
testResult = "Failed"
}
emailext body: '''${FILE, path="report.html"}''',
mimeType: 'text/html',
subject: "[${jenkinsBuildType}]${project}-${env.BRANCH_NAME}-${commitid}-${os}-${testResult}",
to: "${mailList}",
// replyTo: "${mailList}",
recipientProviders: [[$class: 'CulpritsRecipientProvider']]
}// EmailNotification