-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathJenkinsfile
129 lines (121 loc) · 4.9 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
Map matrix_axes = [
hosttype: ['clip'],
media_type: ['live-iso'],
target_name: ['minimal'],
os_name: ['rhel'],
os_version: ['8.2']
]
@NonCPS
List getMatrixAxes(Map matrix_axes) {
List axes = []
Map emptyMap = [:]
List prevCombo = [emptyMap]
for (entry in matrix_axes) {
String axis = entry.key
List values = entry.value
List comboNext = []
for (value in values) {
for(int i = 0; i < prevCombo.size(); i++) {
Map newMap = prevCombo[i].clone()
newMap[axis] = value
comboNext << newMap
}
}
prevCombo = comboNext
}
for (entry in prevCombo) {
for (letter in entry['os_version']) {
entry['os'] = entry['os_name'] + letter
break
}
}
return prevCombo
}
List axes = getMatrixAxes(matrix_axes)
@NonCPS
List getEnvList(Map axis) {
List envList = []
for (entry in axis) {
envList << "${entry.key}=${entry.value}"
}
return envList
}
List getTaskMap(List axes) {
List tasks = []
for(int i = 0; i < axes.size(); i++) {
Map axis = axes[i]
List axisEnv = getEnvList(axis)
String nodeLabel = axis['os'] + " && " + axis['hosttype']
println("nodelabel: " + nodeLabel)
String outerStage = "Build and test " + axis['os'] + "-" + axis['os_version'] + " " + axis['target_name'] + " " + axis['media_type']
String prepareStage = "Prepare " + axis['os'] + "-" + axis['os_version'] + " " + axis['target_name'] + " " + axis['media_type']
String buildStage = "Build " + axis['os'] + "-" + axis['os_version'] + " " + axis['target_name'] + " " + axis['media_type']
String testStage = "Test " + axis['os'] + "-" + axis['os_version'] + " " + axis['target_name'] + " " + axis['media_type']
String repoFile = "CONFIG_REPOS." + axis['os'] + "-" + axis['os_version']
String target_name = axis['target_name']
String media_type = axis['media_type']
Map task = [name:axisEnv.join(', '), job:{ ->
stage outerStage
catchError(message:'stage failed', buildResult:'UNSTABLE', stageResult:'UNSTABLE', catchInterruptions:false) {
// see if a particular node exists. there may be better ways to do this
try {
timeout(time: 2, unit: 'SECONDS') {
node(nodeLabel) {
sh "true"
}
}
} catch (hudson.AbortException err) {
String message = "${err}"
if(message != null && message.contains("Queue task was cancelled")) {
error("No suitable nodes found")
} else {
echo "hudson.AbortException when trying to find node but message is unexpected: message: ${message}"
throw err
}
} catch (err) {
echo "Some random exception when trying to find node: ${err}"
throw err
}
// perform the build and test
try {
timeout(time: 120, unit: 'MINUTES') {
node(nodeLabel) {
sh "sudo rm -rf .* * || true"
checkout scm
if(!fileExists(repoFile)) {
error("No CONFIG_REPO file " + repoFile)
}
sh "cp ${repoFile} CONFIG_REPOS"
try {
sh "make clip-${target_name}-${media_type}"
} catch (err) {
archiveArtifacts(artifacts:"repos/clip-repo/build.log", allowEmptyArchive:true)
throw err
}
archiveArtifacts "*.iso"
sh "./support/tests/media/qemu-test-${media_type}.sh *.iso"
archiveArtifacts(artifacts:"scap", allowEmptyArchive:true)
}
}
} catch (hudson.AbortException err) {
String message = "${err}"
if(message != null && message.contains("Queue task was cancelled")) {
error("Timeout exceeded during build and test")
} else {
echo "Error during build and test: ${message}"
throw err
}
} catch (err) {
echo "Some random exception while running build and test: ${err}"
throw err
}
}
}]
tasks << task
}
return tasks
}
List tasks = getTaskMap(axes)
for (int i=0; i< tasks.size(); i++) {
tasks[i]['job'].call()
}