@@ -21,31 +21,60 @@ pipeline {
21
21
// Each Jenknis Node is connected to said machine via an JAVA agent via an ssh tunnel
22
22
// no op 2
23
23
24
- stage(' Get Machine' ) {
24
+ stage(' 1. Get Machine' ) {
25
25
agent { label ' built-in' }
26
26
steps {
27
27
script {
28
- machine = ' none'
29
- for (label in pullRequest. labels) {
30
- echo " Label: ${ label} "
31
- if ((label. matches(' CI-Hera-Ready' ))) {
32
- machine = ' hera'
33
- } else if ((label. matches(' CI-Orion-Ready' ))) {
34
- machine = ' orion'
35
- } else if ((label. matches(' CI-Hercules-Ready' ))) {
36
- machine = ' hercules'
28
+
29
+ def causes = currentBuild. rawBuild. getCauses()
30
+ def isSpawnedFromAnotherJob = causes. any { cause ->
31
+ cause instanceof hudson.model.Cause.UpstreamCause
32
+ }
33
+
34
+ def run_nodes = []
35
+ if (isSpawnedFromAnotherJob) {
36
+ echo " machine being set to value passed to this spawned job"
37
+ echo " passed machine: ${ params.machine} "
38
+ machine = params. machine
39
+ } else {
40
+ echo " This is parent job so getting list of nodes matching labels:"
41
+ for (label in pullRequest. labels) {
42
+ if (label. matches(" CI-(.*?)-Ready" )) {
43
+ def Machine_name = label. split(' -' )[1 ]. toString()
44
+ jenkins.model.Jenkins . get(). computers. each { c ->
45
+ if (c. node. selfLabel. name == " ${ Machine_name} -EMC" ) {
46
+ run_nodes. add(c. node. selfLabel. name)
47
+ }
48
+ }
49
+ }
37
50
}
38
- } // createing a second machine varible with first letter capital
39
- // because the first letter of the machine name is captitalized in the GitHub labels
40
- Machine = machine[0 ]. toUpperCase() + machine. substring(1 )
51
+ // Spawning all the jobs on the nodes matching the labels
52
+ if (run_nodes. size() > 1 ) {
53
+ run_nodes. init(). each { node ->
54
+ def machine_name = node. split(' -' )[0 ]. toLowerCase()
55
+ echo " Spawning job on node: ${ node} with machine name: ${ machine_name} "
56
+ build job : " /global-workflow/EMC-Global-Pipeline/PR-${ env.CHANGE_ID} " , parameters : [
57
+ string(name : ' machine' , value : machine_name),
58
+ string(name : ' Node' , value : node) ],
59
+ wait : false
60
+ }
61
+ machine = run_nodes. last(). split(' -' )[0 ]. toLowerCase()
62
+ echo " Running parent job: ${ machine} "
63
+ } else {
64
+ machine = run_nodes[0 ]. split(' -' )[0 ]. toLowerCase()
65
+ echo " Running only the parent job: ${ machine} "
66
+ }
67
+ }
41
68
}
42
69
}
43
70
}
44
71
45
- stage(' Get Common Workspace' ) {
72
+ stage(' 2. Get Common Workspace' ) {
46
73
agent { label " ${ machine} -emc" }
47
74
steps {
48
75
script {
76
+ Machine = machine[0 ]. toUpperCase() + machine. substring(1 )
77
+ echo " Getting Common Workspace for ${ Machine} "
49
78
ws(" ${ custom_workspace[machine]} /${ env.CHANGE_ID} " ) {
50
79
properties([parameters([[$class : ' NodeParameterDefinition' , allowedSlaves : [' built-in' , ' Hera-EMC' , ' Orion-EMC' ], defaultSlaves : [' built-in' ], name : ' ' , nodeEligibility : [$class : ' AllNodeEligibility' ], triggerIfResult : ' allCases' ]])])
51
80
HOME = " ${ WORKSPACE} "
@@ -57,7 +86,7 @@ pipeline {
57
86
}
58
87
}
59
88
60
- stage(' Build System' ) {
89
+ stage(' 3. Build System' ) {
61
90
matrix {
62
91
agent { label " ${ machine} -emc" }
63
92
// options {
@@ -141,7 +170,7 @@ pipeline {
141
170
}
142
171
}
143
172
144
- stage(' Run Tests' ) {
173
+ stage(' 4. Run Tests' ) {
145
174
failFast false
146
175
matrix {
147
176
agent { label " ${ machine} -emc" }
@@ -216,7 +245,7 @@ pipeline {
216
245
STATUS = ' Failed'
217
246
try {
218
247
sh(script : """ ${ GH} pr edit ${ env.CHANGE_ID} --repo ${ repo_url} --remove-label "CI-${ Machine} -Running" --add-label "CI-${ Machine} -${ STATUS} " """ , returnStatus : true )
219
- sh(script : """ ${ GH} pr comment ${ env.CHANGE_ID} --repo ${ repo_url} --body "Experiment ${ Case} **FAILED** on ${ Machine} \n in \\ `${ HOME} /RUNTESTS/${ pslot} \\ `" """ )
248
+ sh(script : """ ${ GH} pr comment ${ env.CHANGE_ID} --repo ${ repo_url} --body "Experiment ${ Case} **FAILED** on ${ Machine} in \n \\ `${ HOME} /RUNTESTS/${ pslot} \\ `" """ )
220
249
} catch (Exception e) {
221
250
echo " Failed to update label from Running to ${ STATUS} : ${ e.getMessage()} "
222
251
}
@@ -229,7 +258,7 @@ pipeline {
229
258
}
230
259
}
231
260
}
232
- stage( ' FINALIZE' ) {
261
+ stage( ' 5. FINALIZE' ) {
233
262
when {
234
263
expression {
235
264
STATUS == ' Passed'
0 commit comments