Merge pull request #22736 from dotnet/dev/tomat/copyrights
[platform/upstream/coreclr.git] / netci.groovy
1 // Import the utility functionality.
2
3 import jobs.generation.*
4
5 // The input project name (e.g. dotnet/coreclr)
6 def project = GithubProject
7 // The input branch name (e.g. master)
8 def branch = GithubBranchName
9 def projectFolder = Utilities.getFolderName(project) + '/' + Utilities.getFolderName(branch)
10
11 // Create a folder for JIT stress jobs and associated folder views
12 folder('jitstress')
13 Utilities.addStandardFolderView(this, 'jitstress', project)
14
15 // Create a folder for testing via illink
16 folder('illink')
17 Utilities.addStandardFolderView(this, 'illink', project)
18
19 def static getOSGroup(def os) {
20     def osGroupMap = ['Ubuntu'      : 'Linux',
21                       'Ubuntu16.04' : 'Linux',
22                       'Ubuntu16.10' : 'Linux',
23                       'RHEL7.2'     : 'Linux',
24                       'Debian8.4'   : 'Linux',
25                       'Fedora24'    : 'Linux',
26                       'CentOS7.1'   : 'Linux',
27                       'Tizen'       : 'Linux',
28                       'OSX10.12'    : 'OSX',
29                       'Windows_NT'  : 'Windows_NT']
30     def osGroup = osGroupMap.get(os, null)
31     assert osGroup != null : "Could not find os group for ${os}"
32     return osGroupMap[os]
33 }
34
35 // We use this class (vs variables) so that the static functions can access data here.
36 class Constants {
37
38     // We have very limited Windows ARM64 hardware (used for ARM/ARM64 testing) and Linux/arm32 and Linux/arm64 hardware.
39     // So only allow certain branches to use it.
40     def static LimitedHardwareBranches = [
41                'master']
42
43     // Innerloop build OS's
44     // The Windows_NT_BuildOnly OS is a way to speed up the Non-Windows builds by avoiding
45     // test execution in the build flow runs.  It generates the exact same build
46     // as Windows_NT but without running the tests.
47     def static osList = [
48                'Ubuntu',
49                'Debian8.4',
50                'OSX10.12',
51                'Windows_NT',
52                'Windows_NT_BuildOnly',
53                'CentOS7.1',
54                'RHEL7.2',
55                'Ubuntu16.04',
56                'Ubuntu16.10',
57                'Fedora24',
58                'Tizen']
59
60     def static crossList = [
61                'Ubuntu',
62                'Debian8.4',
63                'OSX10.12',
64                'Windows_NT',
65                'CentOS7.1',
66                'RHEL7.2']
67
68     // This is a set of JIT stress modes combined with the set of variables that
69     // need to be set to actually enable that stress mode.  The key of the map is the stress mode and
70     // the values are the environment variables
71     def static jitStressModeScenarios = [
72                'minopts'                        : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JITMinOpts' : '1'],
73                'tieredcompilation'              : ['COMPlus_TieredCompilation' : '1'], // this can be removed once tiered compilation is on by default
74                'no_tiered_compilation'          : ['COMPlus_TieredCompilation' : '0'],
75                'no_tiered_compilation_innerloop': ['COMPlus_TieredCompilation' : '0'],
76                'forcerelocs'                    : ['COMPlus_TieredCompilation' : '0', 'COMPlus_ForceRelocs' : '1'],
77                'jitstress1'                     : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '1'],
78                'jitstress2'                     : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2'],
79                'jitstress1_tiered'              : ['COMPlus_TieredCompilation' : '1', 'COMPlus_JitStress' : '1'],
80                'jitstress2_tiered'              : ['COMPlus_TieredCompilation' : '1', 'COMPlus_JitStress' : '2'],
81                'jitstressregs1'                 : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '1'],
82                'jitstressregs2'                 : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '2'],
83                'jitstressregs3'                 : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '3'],
84                'jitstressregs4'                 : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '4'],
85                'jitstressregs8'                 : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '8'],
86                'jitstressregs0x10'              : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '0x10'],
87                'jitstressregs0x80'              : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '0x80'],
88                'jitstressregs0x1000'            : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '0x1000'],
89                'jitstress2_jitstressregs1'      : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '1'],
90                'jitstress2_jitstressregs2'      : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '2'],
91                'jitstress2_jitstressregs3'      : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '3'],
92                'jitstress2_jitstressregs4'      : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '4'],
93                'jitstress2_jitstressregs8'      : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '8'],
94                'jitstress2_jitstressregs0x10'   : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '0x10'],
95                'jitstress2_jitstressregs0x80'   : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '0x80'],
96                'jitstress2_jitstressregs0x1000' : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '0x1000'],
97                'tailcallstress'                 : ['COMPlus_TieredCompilation' : '0', 'COMPlus_TailcallStress' : '1'],
98                'jitsse2only'                    : ['COMPlus_TieredCompilation' : '0', 'COMPlus_EnableAVX' : '0', 'COMPlus_EnableSSE3_4' : '0'],
99                'jitnosimd'                      : ['COMPlus_TieredCompilation' : '0', 'COMPlus_FeatureSIMD' : '0'],
100                'jitincompletehwintrinsic'       : ['COMPlus_TieredCompilation' : '0', 'COMPlus_EnableIncompleteISAClass' : '1'],
101                'jitx86hwintrinsicnoavx'         : ['COMPlus_TieredCompilation' : '0', 'COMPlus_EnableIncompleteISAClass' : '1', 'COMPlus_EnableAVX' : '0'], // testing the legacy SSE encoding
102                'jitx86hwintrinsicnoavx2'        : ['COMPlus_TieredCompilation' : '0', 'COMPlus_EnableIncompleteISAClass' : '1', 'COMPlus_EnableAVX2' : '0'], // testing SNB/IVB
103                'jitx86hwintrinsicnosimd'        : ['COMPlus_TieredCompilation' : '0', 'COMPlus_EnableIncompleteISAClass' : '1', 'COMPlus_FeatureSIMD' : '0'], // match "jitnosimd", may need to remove after decoupling HW intrinsic from FeatureSIMD
104                'jitnox86hwintrinsic'            : ['COMPlus_TieredCompilation' : '0', 'COMPlus_EnableIncompleteISAClass' : '1', 'COMPlus_EnableSSE' : '0' , 'COMPlus_EnableSSE2' : '0' , 'COMPlus_EnableSSE3' : '0' , 'COMPlus_EnableSSSE3' : '0' , 'COMPlus_EnableSSE41' : '0' , 'COMPlus_EnableSSE42' : '0' , 'COMPlus_EnableAVX' : '0' , 'COMPlus_EnableAVX2' : '0' , 'COMPlus_EnableAES' : '0' , 'COMPlus_EnableBMI1' : '0' , 'COMPlus_EnableBMI2' : '0' , 'COMPlus_EnableFMA' : '0' , 'COMPlus_EnableLZCNT' : '0' , 'COMPlus_EnablePCLMULQDQ' : '0' , 'COMPlus_EnablePOPCNT' : '0'],
105                'corefx_baseline'                : ['COMPlus_TieredCompilation' : '0'], // corefx baseline
106                'corefx_minopts'                 : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JITMinOpts' : '1'],
107                'corefx_tieredcompilation'       : ['COMPlus_TieredCompilation' : '1'],  // this can be removed once tiered compilation is on by default
108                'corefx_jitstress1'              : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '1'],
109                'corefx_jitstress2'              : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStress' : '2'],
110                'corefx_jitstressregs1'          : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '1'],
111                'corefx_jitstressregs2'          : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '2'],
112                'corefx_jitstressregs3'          : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '3'],
113                'corefx_jitstressregs4'          : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '4'],
114                'corefx_jitstressregs8'          : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '8'],
115                'corefx_jitstressregs0x10'       : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '0x10'],
116                'corefx_jitstressregs0x80'       : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '0x80'],
117                'corefx_jitstressregs0x1000'     : ['COMPlus_TieredCompilation' : '0', 'COMPlus_JitStressRegs' : '0x1000'],
118                'gcstress0x3'                    : ['COMPlus_TieredCompilation' : '0', 'COMPlus_GCStress' : '0x3'],
119                'gcstress0xc'                    : ['COMPlus_TieredCompilation' : '0', 'COMPlus_GCStress' : '0xC'],
120                'zapdisable'                     : ['COMPlus_TieredCompilation' : '0', 'COMPlus_ZapDisable' : '1', 'COMPlus_ReadyToRun' : '0'],
121                'heapverify1'                    : ['COMPlus_TieredCompilation' : '0', 'COMPlus_HeapVerify' : '1'],
122                'gcstress0xc_zapdisable'             : ['COMPlus_TieredCompilation' : '0', 'COMPlus_GCStress' : '0xC', 'COMPlus_ZapDisable' : '1', 'COMPlus_ReadyToRun' : '0'],
123                'gcstress0xc_zapdisable_jitstress2'  : ['COMPlus_TieredCompilation' : '0', 'COMPlus_GCStress' : '0xC', 'COMPlus_ZapDisable' : '1', 'COMPlus_ReadyToRun' : '0', 'COMPlus_JitStress'  : '2'],
124                'gcstress0xc_zapdisable_heapverify1' : ['COMPlus_TieredCompilation' : '0', 'COMPlus_GCStress' : '0xC', 'COMPlus_ZapDisable' : '1', 'COMPlus_ReadyToRun' : '0', 'COMPlus_HeapVerify' : '1'],
125                'gcstress0xc_jitstress1'             : ['COMPlus_TieredCompilation' : '0', 'COMPlus_GCStress' : '0xC', 'COMPlus_JitStress'  : '1'],
126                'gcstress0xc_jitstress2'             : ['COMPlus_TieredCompilation' : '0', 'COMPlus_GCStress' : '0xC', 'COMPlus_JitStress'  : '2'],
127                'gcstress0xc_minopts_heapverify1'    : ['COMPlus_TieredCompilation' : '0', 'COMPlus_GCStress' : '0xC', 'COMPlus_JITMinOpts' : '1', 'COMPlus_HeapVerify' : '1']
128     ]
129
130     // This is a set of ReadyToRun stress scenarios
131     def static r2rStressScenarios = [
132                'r2r_jitstress1'             : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStress": "1"],
133                'r2r_jitstress2'             : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStress": "2"],
134                'r2r_jitstress1_tiered'      : ['COMPlus_TieredCompilation' : '1', "COMPlus_JitStress": "1"],
135                'r2r_jitstress2_tiered'      : ['COMPlus_TieredCompilation' : '1', "COMPlus_JitStress": "2"],
136                'r2r_jitstressregs1'         : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStressRegs": "1"],
137                'r2r_jitstressregs2'         : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStressRegs": "2"],
138                'r2r_jitstressregs3'         : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStressRegs": "3"],
139                'r2r_jitstressregs4'         : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStressRegs": "4"],
140                'r2r_jitstressregs8'         : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStressRegs": "8"],
141                'r2r_jitstressregs0x10'      : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStressRegs": "0x10"],
142                'r2r_jitstressregs0x80'      : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStressRegs": "0x80"],
143                'r2r_jitstressregs0x1000'    : ['COMPlus_TieredCompilation' : '0', "COMPlus_JitStressRegs": "0x1000"],
144                'r2r_jitminopts'             : ['COMPlus_TieredCompilation' : '0', "COMPlus_JITMinOpts": "1"], 
145                'r2r_jitforcerelocs'         : ['COMPlus_TieredCompilation' : '0', "COMPlus_ForceRelocs": "1"],
146                'r2r_gcstress15'             : ['COMPlus_TieredCompilation' : '0', "COMPlus_GCStress": "0xF"],
147                'r2r_no_tiered_compilation'  : ['COMPlus_TieredCompilation' : '0'],
148     ]
149
150     // This is the basic set of scenarios
151     def static basicScenarios = [
152                'innerloop',
153                'normal',
154                'ilrt',
155                'r2r',
156                'longgc',
157                'formatting',
158                'gcsimulator',
159                // 'jitdiff', // jitdiff is currently disabled, until someone spends the effort to make it fully work
160                'standalone_gc',
161                'gc_reliability_framework',
162                'illink',
163                'corefx_innerloop',
164                'crossgen_comparison',
165                'pmi_asm_diffs']
166
167     def static allScenarios = basicScenarios + r2rStressScenarios.keySet() + jitStressModeScenarios.keySet()
168
169     // Valid PR trigger combinations.
170     def static prTriggeredValidInnerLoopCombos = [
171         'Windows_NT': [
172             'x64': [
173                 'Checked'
174             ], 
175             'x86': [
176                 'Checked',
177                 'Release'
178             ], 
179             'arm': [
180                 'Debug',
181                 'Checked'
182             ],
183             'arm64': [
184                 'Debug',
185                 'Checked'
186             ]
187         ],
188         'Windows_NT_BuildOnly': [
189             'x64': [
190                 'Checked',
191                 'Release'
192             ],
193             'x86': [
194                 'Checked',
195                 'Release'
196             ], 
197             'arm': [
198                 'Checked'
199             ], 
200         ],
201         'Ubuntu': [
202             'x64': [
203                 'Checked'
204             ],
205             'arm': [
206                 'Checked'
207             ]
208         ],
209         'Ubuntu16.04': [
210             'arm64': [
211                 'Checked'
212             ]
213         ],
214         'CentOS7.1': [
215             'x64': [
216                 'Debug',
217                 'Checked'
218             ]
219         ],
220         'OSX10.12': [
221             'x64': [
222                 'Checked'
223             ]
224         ]
225     ]
226
227     // A set of scenarios that are valid for arm/arm64 tests run on hardware. This is a map from valid scenario name
228     // to Tests.lst file categories to exclude.
229     //
230     // This list should contain a subset of the scenarios from `allScenarios`. Please keep this in the same order as that,
231     // and with the same values, with some commented out, for easier maintenance.
232     //
233     // Note that some scenarios that are commented out should be enabled, but haven't yet been.
234     //
235     def static validArmWindowsScenarios = [
236                'innerloop',
237                'normal',
238                // 'ilrt'
239                'r2r',
240                // 'longgc'
241                // 'formatting'
242                // 'gcsimulator'
243                // 'jitdiff'
244                // 'standalone_gc'
245                // 'gc_reliability_framework'
246                // 'illink'
247                // 'corefx_innerloop'
248                // 'crossgen_comparison'
249                // 'pmi_asm_diffs'
250                'r2r_jitstress1',
251                'r2r_jitstress2',
252                'r2r_jitstress1_tiered',
253                'r2r_jitstress2_tiered',
254                'r2r_jitstressregs1',
255                'r2r_jitstressregs2',
256                'r2r_jitstressregs3',
257                'r2r_jitstressregs4',
258                'r2r_jitstressregs8',
259                'r2r_jitstressregs0x10',
260                'r2r_jitstressregs0x80',
261                'r2r_jitstressregs0x1000',
262                'r2r_jitminopts',
263                'r2r_jitforcerelocs',
264                'r2r_gcstress15',
265                'r2r_no_tiered_compilation',
266                'minopts',
267                'tieredcompilation',
268                'no_tiered_compilation',
269                'no_tiered_compilation_innerloop',
270                'forcerelocs',
271                'jitstress1',
272                'jitstress2',
273                'jitstress1_tiered',
274                'jitstress2_tiered',
275                'jitstressregs1',
276                'jitstressregs2',
277                'jitstressregs3',
278                'jitstressregs4',
279                'jitstressregs8',
280                'jitstressregs0x10',
281                'jitstressregs0x80',
282                'jitstressregs0x1000',
283                'jitstress2_jitstressregs1',
284                'jitstress2_jitstressregs2',
285                'jitstress2_jitstressregs3',
286                'jitstress2_jitstressregs4',
287                'jitstress2_jitstressregs8',
288                'jitstress2_jitstressregs0x10',
289                'jitstress2_jitstressregs0x80',
290                'jitstress2_jitstressregs0x1000',
291                'tailcallstress',
292                // 'jitsse2only'                     // Only relevant to xarch
293                'jitnosimd',                         // Only interesting on platforms where SIMD support exists.
294                // 'jitincompletehwintrinsic'
295                // 'jitx86hwintrinsicnoavx'
296                // 'jitx86hwintrinsicnoavx2'
297                // 'jitx86hwintrinsicnosimd'
298                // 'jitnox86hwintrinsic'
299                'corefx_baseline',                   // corefx tests don't use smarty
300                'corefx_minopts',                    // corefx tests don't use smarty
301                'corefx_tieredcompilation',          // corefx tests don't use smarty
302                'corefx_jitstress1',                 // corefx tests don't use smarty
303                'corefx_jitstress2',                 // corefx tests don't use smarty
304                'corefx_jitstressregs1',             // corefx tests don't use smarty
305                'corefx_jitstressregs2',             // corefx tests don't use smarty
306                'corefx_jitstressregs3',             // corefx tests don't use smarty
307                'corefx_jitstressregs4',             // corefx tests don't use smarty
308                'corefx_jitstressregs8',             // corefx tests don't use smarty
309                'corefx_jitstressregs0x10',          // corefx tests don't use smarty
310                'corefx_jitstressregs0x80',          // corefx tests don't use smarty
311                'corefx_jitstressregs0x1000',        // corefx tests don't use smarty
312                'gcstress0x3',
313                'gcstress0xc',
314                'zapdisable',
315                'heapverify1',
316                'gcstress0xc_zapdisable',
317                'gcstress0xc_zapdisable_jitstress2',
318                'gcstress0xc_zapdisable_heapverify1',
319                'gcstress0xc_jitstress1',
320                'gcstress0xc_jitstress2',
321                'gcstress0xc_minopts_heapverify1',
322
323                //
324                // NOTE: the following scenarios are not defined in the 'allScenarios' list! Is this a bug?
325                //
326
327                'minopts_zapdisable',
328                'gcstress0x3_jitstress1',
329                'gcstress0x3_jitstress2',
330                'gcstress0x3_jitstressregs1',
331                'gcstress0x3_jitstressregs2',
332                'gcstress0x3_jitstressregs3',
333                'gcstress0x3_jitstressregs4',
334                'gcstress0x3_jitstressregs8',
335                'gcstress0x3_jitstressregs0x10',
336                'gcstress0x3_jitstressregs0x80',
337                'gcstress0x3_jitstressregs0x1000',
338                'gcstress0xc_jitstressregs1',
339                'gcstress0xc_jitstressregs2',
340                'gcstress0xc_jitstressregs3',
341                'gcstress0xc_jitstressregs4',
342                'gcstress0xc_jitstressregs8',
343                'gcstress0xc_jitstressregs0x10',
344                'gcstress0xc_jitstressregs0x80',
345                'gcstress0xc_jitstressregs0x1000'
346     ]
347   
348     def static validLinuxArmScenarios = [
349                'innerloop',
350                'normal',
351                // 'ilrt'
352                'r2r',
353                // 'longgc'
354                // 'formatting'
355                // 'gcsimulator'
356                // 'jitdiff'
357                // 'standalone_gc'
358                // 'gc_reliability_framework'
359                // 'illink'
360                // 'corefx_innerloop'
361                'crossgen_comparison',
362                'pmi_asm_diffs',
363                'r2r_jitstress1',
364                'r2r_jitstress2',
365                'r2r_jitstress1_tiered',
366                'r2r_jitstress2_tiered',
367                'r2r_jitstressregs1',
368                'r2r_jitstressregs2',
369                'r2r_jitstressregs3',
370                'r2r_jitstressregs4',
371                'r2r_jitstressregs8',
372                'r2r_jitstressregs0x10',
373                'r2r_jitstressregs0x80',
374                'r2r_jitstressregs0x1000',
375                'r2r_jitminopts',
376                'r2r_jitforcerelocs',
377                'r2r_gcstress15',
378                'r2r_no_tiered_compilation',
379                'minopts',
380                'tieredcompilation',
381                'no_tiered_compilation',
382                'no_tiered_compilation_innerloop',
383                'forcerelocs',
384                'jitstress1',
385                'jitstress2',
386                'jitstress1_tiered',
387                'jitstress2_tiered',
388                'jitstressregs1',
389                'jitstressregs2',
390                'jitstressregs3',
391                'jitstressregs4',
392                'jitstressregs8',
393                'jitstressregs0x10',
394                'jitstressregs0x80',
395                'jitstressregs0x1000',
396                'jitstress2_jitstressregs1',
397                'jitstress2_jitstressregs2',
398                'jitstress2_jitstressregs3',
399                'jitstress2_jitstressregs4',
400                'jitstress2_jitstressregs8',
401                'jitstress2_jitstressregs0x10',
402                'jitstress2_jitstressregs0x80',
403                'jitstress2_jitstressregs0x1000',
404                'tailcallstress',
405                // 'jitsse2only'                          // Only relevant to xarch
406                // 'jitnosimd'                            // Only interesting on platforms where SIMD support exists.
407                // 'jitincompletehwintrinsic'
408                // 'jitx86hwintrinsicnoavx'
409                // 'jitx86hwintrinsicnoavx2'
410                // 'jitx86hwintrinsicnosimd'
411                // 'jitnox86hwintrinsic'
412                'corefx_baseline',
413                'corefx_minopts',
414                'corefx_tieredcompilation',
415                'corefx_jitstress1',
416                'corefx_jitstress2',
417                'corefx_jitstressregs1',
418                'corefx_jitstressregs2',
419                'corefx_jitstressregs3',
420                'corefx_jitstressregs4',
421                'corefx_jitstressregs8',
422                'corefx_jitstressregs0x10',
423                'corefx_jitstressregs0x80',
424                'corefx_jitstressregs0x1000',
425                'gcstress0x3',
426                'gcstress0xc',
427                'zapdisable',
428                'heapverify1',
429                'gcstress0xc_zapdisable',
430                'gcstress0xc_zapdisable_jitstress2',
431                'gcstress0xc_zapdisable_heapverify1',
432                'gcstress0xc_jitstress1',
433                'gcstress0xc_jitstress2',
434                'gcstress0xc_minopts_heapverify1'
435     ]
436
437     def static validLinuxArm64Scenarios = [
438                'innerloop',
439                'normal',
440                // 'ilrt'
441                'r2r',
442                // 'longgc'
443                // 'formatting'
444                // 'gcsimulator'
445                // 'jitdiff'
446                // 'standalone_gc'
447                // 'gc_reliability_framework'
448                // 'illink'
449                // 'corefx_innerloop'
450                'crossgen_comparison',
451                'pmi_asm_diffs',
452                'r2r_jitstress1',
453                'r2r_jitstress2',
454                'r2r_jitstress1_tiered',
455                'r2r_jitstress2_tiered',
456                'r2r_jitstressregs1',
457                'r2r_jitstressregs2',
458                'r2r_jitstressregs3',
459                'r2r_jitstressregs4',
460                'r2r_jitstressregs8',
461                'r2r_jitstressregs0x10',
462                'r2r_jitstressregs0x80',
463                'r2r_jitstressregs0x1000',
464                'r2r_jitminopts',
465                'r2r_jitforcerelocs',
466                'r2r_gcstress15',
467                'r2r_no_tiered_compilation',
468                'minopts',
469                'tieredcompilation',
470                'no_tiered_compilation',
471                'no_tiered_compilation_innerloop',
472                'forcerelocs',
473                'jitstress1',
474                'jitstress2',
475                'jitstress1_tiered',
476                'jitstress2_tiered',
477                'jitstressregs1',
478                'jitstressregs2',
479                'jitstressregs3',
480                'jitstressregs4',
481                'jitstressregs8',
482                'jitstressregs0x10',
483                'jitstressregs0x80',
484                'jitstressregs0x1000',
485                'jitstress2_jitstressregs1',
486                'jitstress2_jitstressregs2',
487                'jitstress2_jitstressregs3',
488                'jitstress2_jitstressregs4',
489                'jitstress2_jitstressregs8',
490                'jitstress2_jitstressregs0x10',
491                'jitstress2_jitstressregs0x80',
492                'jitstress2_jitstressregs0x1000',
493                'tailcallstress',
494                // 'jitsse2only'                         // Only relevant to xarch
495                'jitnosimd',                             // Only interesting on platforms where SIMD support exists.
496                // 'jitincompletehwintrinsic'
497                // 'jitx86hwintrinsicnoavx'
498                // 'jitx86hwintrinsicnoavx2'
499                // 'jitx86hwintrinsicnosimd'
500                // 'jitnox86hwintrinsic'
501                'corefx_baseline',
502                'corefx_minopts',
503                'corefx_tieredcompilation',
504                'corefx_jitstress1',
505                'corefx_jitstress2',
506                'corefx_jitstressregs1',
507                'corefx_jitstressregs2',
508                'corefx_jitstressregs3',
509                'corefx_jitstressregs4',
510                'corefx_jitstressregs8',
511                'corefx_jitstressregs0x10',
512                'corefx_jitstressregs0x80',
513                'corefx_jitstressregs0x1000',
514                'gcstress0x3',
515                'gcstress0xc',
516                'zapdisable',
517                'heapverify1',
518                'gcstress0xc_zapdisable',
519                'gcstress0xc_zapdisable_jitstress2',
520                'gcstress0xc_zapdisable_heapverify1',
521                'gcstress0xc_jitstress1',
522                'gcstress0xc_jitstress2',
523                'gcstress0xc_minopts_heapverify1'
524     ]
525
526     def static configurationList = ['Debug', 'Checked', 'Release']
527
528     // This is the set of architectures
529     // Some of these are pseudo-architectures:
530     //    armem -- ARM builds/runs using an emulator. Used for Tizen runs.
531     def static architectureList = ['arm', 'armem', 'arm64', 'x64', 'x86']
532
533     // This set of architectures that cross build on Windows and run on Windows ARM64 hardware.
534     def static armWindowsCrossArchitectureList = ['arm', 'arm64']
535 }
536
537 // **************************************************************
538 // Create some specific views
539 // 
540 // These aren't using the Utilities.addStandardFolderView() function, because that creates
541 // views based on a single regular expression. These views will be generated by adding a
542 // specific set of jobs to them.
543 //
544 // Utilities.addStandardFolderView() also creates a lot of additional stuff around the
545 // view, like "Build Statistics", "Job Statistics", "Unstable Jobs". Until it is determined
546 // those are required, don't add them (which simplifies the view pages, as well).
547 // **************************************************************
548
549 class Views {
550     def static MergeJobView = null
551     def static PeriodicJobView = null
552     def static ArchitectureViews = [:]
553     def static OSViews = [:]
554 }
555
556 // MergeJobView: include all jobs that execute when a PR change is merged.
557 Views.MergeJobView = listView('Merge') {
558     recurse()
559     columns {
560         status()
561         weather()
562         name()
563         lastSuccess()
564         lastFailure()
565         lastDuration()
566         buildButton()
567     }
568 }
569
570 // PeriodicJobView: include all jobs that execute on a schedule
571 Views.PeriodicJobView = listView('Periodic') {
572     recurse()
573     columns {
574         status()
575         weather()
576         name()
577         lastSuccess()
578         lastFailure()
579         lastDuration()
580         buildButton()
581     }
582 }
583
584 // Create a view for non-PR jobs for each architecture.
585 Constants.architectureList.each { architecture ->
586     Views.ArchitectureViews[architecture] = listView(architecture) {
587         recurse()
588         columns {
589             status()
590             weather()
591             name()
592             lastSuccess()
593             lastFailure()
594             lastDuration()
595             buildButton()
596         }
597     }
598 }
599
600 // Create a view for non-PR jobs for each OS.
601 Constants.osList.each { os ->
602     // Don't create one for the special 'Windows_NT_BuildOnly'
603     if (os == 'Windows_NT_BuildOnly') {
604         return
605     }
606     Views.OSViews[os] = listView(os) {
607         recurse()
608         columns {
609             status()
610             weather()
611             name()
612             lastSuccess()
613             lastFailure()
614             lastDuration()
615             buildButton()
616         }
617     }
618 }
619
620 def static addToMergeView(def job) {
621     Views.MergeJobView.with {
622         jobs {
623             name(job.name)
624         }
625     }
626 }
627
628 def static addToPeriodicView(def job) {
629     Views.PeriodicJobView.with {
630         jobs {
631             name(job.name)
632         }
633     }
634 }
635
636 def static addToViews(def job, def isFlowJob, def isPR, def architecture, def os, def configuration, def scenario) {
637     if (isPR) {
638         // No views want PR jobs currently.
639         return
640     }
641
642     // We don't want to include in view any job that is only used by a flow job (because we want the views to have only the
643     // "top-level" jobs. Build only jobs are such jobs.
644     if (os == 'Windows_NT_BuildOnly') {
645         return
646     }
647
648     if (!isFlowJob) {
649         // For non-flow jobs, which ones are only used by flow jobs?
650         if ((architecture == 'arm') || (architecture == 'arm64')) {
651             if (isCoreFxScenario(scenario)) {
652                 // We have corefx-specific scenario builds for each of the runs, but these are driven by flow jobs.
653                 return
654             }
655
656             // We're left with the basic normal/innerloop builds. We might want to remove these from the views also, if desired.
657             // However, there are a few, like the Debug Build, that is build only, not "Build and Test", that we should leave.
658         }
659     }
660
661     // Add to architecture view.
662     Views.ArchitectureViews[architecture].with {
663         jobs {
664             name(job.name)
665         }
666     }
667
668     // Add to OS view.
669     Views.OSViews[os].with {
670         jobs {
671             name(job.name)
672         }
673     }
674 }
675
676 def static addPeriodicTriggerHelper(def job, String cronString, boolean alwaysRuns = false) {
677     addToPeriodicView(job)
678     Utilities.addPeriodicTrigger(job, cronString, alwaysRuns)
679 }
680
681 def static addGithubPushTriggerHelper(def job) {
682     addToMergeView(job)
683     Utilities.addGithubPushTrigger(job)
684 }
685
686
687 def static setMachineAffinity(def job, def os, def architecture, def options = null) {
688     assert os instanceof String
689     assert architecture instanceof String
690
691     def armArches = ['arm', 'armem', 'arm64']
692
693     if (!(architecture in armArches)) {
694         assert options == null
695         Utilities.setMachineAffinity(job, os, 'latest-or-auto')
696
697         return
698     }
699
700     // This is an arm(64) job.
701     //
702     // There are several options.
703     //
704     // Windows_NT
705     // 
706     // Arm32 (Build) -> latest-arm64
707     //       |-> os == "Windows_NT" && (architecture == "arm") && options['use_arm64_build_machine'] == true
708     // Arm32 (Test)  -> arm64-windows_nt
709     //       |-> os == "Windows_NT" && (architecture == "arm") && options['use_arm64_build_machine'] == false
710     //
711     // Arm64 (Build) -> latest-arm64
712     //       |-> os == "Windows_NT" && architecture == "arm64" && options['use_arm64_build_machine'] == true
713     // Arm64 (Test)  -> arm64-windows_nt
714     //       |-> os == "Windows_NT" && architecture == "arm64" && options['use_arm64_build_machine'] == false
715     //
716     // Ubuntu
717     //
718     // Arm32 emulator (Build, Test) -> arm-cross-latest
719     //       |-> os == "Tizen" && (architecture == "armem")
720     //
721     // Arm32 hardware (Flow) -> Ubuntu 16.04 latest-or-auto (don't use limited arm hardware)
722     //       |-> os == "Ubuntu" && (architecture == "arm") && options['is_flow_job'] == true
723     // Arm32 hardware (Build) -> Ubuntu 16.04 latest-or-auto
724     //       |-> os == "Ubuntu" && (architecture == "arm") && options['is_build_job'] == true
725     // Arm32 hardware (Test) -> Helix ubuntu.1404.arm32.open queue
726     //       |-> os == "Ubuntu" && (architecture == "arm")
727     //
728     // Arm64 (Build) -> arm64-cross-latest
729     //       |-> os != "Windows_NT" && architecture == "arm64" && options['is_build_job'] == true
730     // Arm64 (Test) -> Helix Ubuntu.1604.Arm64.Iron.Open queue
731     //       |-> os != "Windows_NT" && architecture == "arm64"
732     //
733     // Note: we are no longer using Jenkins tags "arm64-huge-page-size", "arm64-small-page-size".
734     // Support for Linux arm64 large page size has been removed for now, as it wasn't being used.
735     //
736     // Note: we are no longer using Jenkins tag 'latest-arm64' for arm/arm64 Windows build machines. Instead,
737     // we are using public VS2017 arm/arm64 tools in a VM from Helix.
738
739     // This has to be a arm arch
740     assert architecture in armArches
741     if (os == "Windows_NT") {
742         // arm32/arm64 Windows jobs share the same machines for now
743         def isBuild = options['use_arm64_build_machine'] == true
744
745         if (isBuild == true) {
746             job.with {
747                 label('Windows.10.Amd64.ClientRS4.DevEx.Open')
748             }
749         } else {
750             Utilities.setMachineAffinity(job, 'windows.10.arm64.open')
751         }
752     } else {
753         assert os != 'Windows_NT'
754
755         if (architecture == 'armem') {
756             // arm emulator (Tizen). Build and test on same machine,
757             // using Docker.
758             assert os == 'Tizen'
759             Utilities.setMachineAffinity(job, 'Ubuntu', 'arm-cross-latest')
760         }
761         else {
762             // arm/arm64 Ubuntu on hardware.
763             assert architecture == 'arm' || architecture == 'arm64'
764             def isFlow  = (options != null) && (options['is_flow_job'] == true)
765             def isBuild = (options != null) && (options['is_build_job'] == true)
766             if (isFlow || isBuild) {
767                 // arm/arm64 Ubuntu build machine. Build uses docker, so the actual host OS is not
768                 // very important. Therefore, use latest or auto. Flow jobs don't need to use arm hardware.
769                 Utilities.setMachineAffinity(job, 'Ubuntu16.04', 'latest-or-auto')
770             } else {
771                 // arm/arm64 Ubuntu test machine. Specify the Helix queue name here.
772                 if (architecture == 'arm64') {
773                     assert os == 'Ubuntu16.04'
774                     job.with {
775                         label('Ubuntu.1604.Arm64.Iron.Open')
776                     }
777                 }
778                 else {
779                     assert os == 'Ubuntu'
780                     job.with {
781                         label('ubuntu.1404.arm32.open')
782                     }
783                 }
784             }
785         }
786     }
787 }
788
789 // setJobMachineAffinity: compute the machine affinity options for a job,
790 // then set the job with those affinity options.
791 def static setJobMachineAffinity(def architecture, def os, def isBuildJob, def isTestJob, def isFlowJob, def job)
792 {
793     assert (isBuildJob  && !isTestJob && !isFlowJob) ||
794            (!isBuildJob && isTestJob  && !isFlowJob) ||
795            (!isBuildJob && !isTestJob && isFlowJob)
796
797     def affinityOptions = null
798     def affinityArchitecture = architecture
799
800     if (os == "Windows_NT") {
801         if (architecture in Constants.armWindowsCrossArchitectureList) {
802             if (isBuildJob) {
803                 affinityOptions = [ "use_arm64_build_machine" : true ]
804             } else if (isTestJob) {
805                 affinityOptions = [ "use_arm64_build_machine" : false ]
806             } else if (isFlowJob) {
807                 // For the flow jobs set the machine affinity as x64
808                 affinityArchitecture = 'x64'
809             }
810         }
811     }
812     else {
813         if ((architecture == 'arm64') || (architecture == 'arm')) {
814             if (isBuildJob) {
815                 affinityOptions = ['is_build_job': true]
816             } else if (isFlowJob) {
817                 affinityOptions = ['is_flow_job': true]
818             }
819         }
820     }
821
822     setMachineAffinity(job, os, affinityArchitecture, affinityOptions)
823 }
824
825 def static isGCStressRelatedTesting(def scenario) {
826     // The 'r2r_gcstress15' scenario is a basic scenario.
827     // Detect it and make it a GCStress related.
828     if (scenario == 'r2r_gcstress15')
829     {
830         return true;
831     }
832
833     def gcStressTestEnvVars = [ 'COMPlus_GCStress', 'COMPlus_ZapDisable', 'COMPlus_HeapVerify']
834     def scenarioName = scenario.toLowerCase()
835     def isGCStressTesting = false
836     Constants.jitStressModeScenarios[scenario].each{ k, v ->
837         if (k in gcStressTestEnvVars) {
838             isGCStressTesting = true;
839         }
840     }
841     return isGCStressTesting
842 }
843
844 def static isCoreFxScenario(def scenario) {
845     def corefx_prefix = 'corefx_'
846     if (scenario.length() < corefx_prefix.length()) {
847         return false
848     }
849     return scenario.substring(0,corefx_prefix.length()) == corefx_prefix
850 }
851
852 def static isR2RBaselineScenario(def scenario) {
853     return (scenario == 'r2r')
854 }
855
856 def static isR2RStressScenario(def scenario) {
857     return Constants.r2rStressScenarios.containsKey(scenario)
858 }
859
860 def static isR2RScenario(def scenario) {
861     return isR2RBaselineScenario(scenario) || isR2RStressScenario(scenario)
862 }
863
864 def static isJitStressScenario(def scenario) {
865     return Constants.jitStressModeScenarios.containsKey(scenario)
866 }
867
868 def static isLongGc(def scenario) {
869     return (scenario == 'longgc' || scenario == 'gcsimulator')
870 }
871
872 def static isJitDiff(def scenario) {
873     return (scenario == 'jitdiff')
874 }
875
876 def static isGcReliabilityFramework(def scenario) {
877     return (scenario == 'gc_reliability_framework')
878 }
879
880 def static isArmWindowsScenario(def scenario) {
881     return Constants.validArmWindowsScenarios.contains(scenario)
882 }
883
884 def static isValidPrTriggeredInnerLoopJob(os, architecture, configuration, isBuildOnly) {
885     if (isBuildOnly == true) {
886         os = 'Windows_NT_BuildOnly'
887     }
888
889     def validOsPrTriggerArchConfigs = Constants.prTriggeredValidInnerLoopCombos[os]
890     if (validOsPrTriggerArchConfigs != null) {
891         def validOsPrTriggerConfigs = validOsPrTriggerArchConfigs[architecture]
892         if (validOsPrTriggerConfigs != null) {
893             if (configuration in validOsPrTriggerConfigs) {
894                 return true
895             }
896         }
897     }
898
899     return false
900 }
901
902 // This means the job builds and runs the 'innerloop' test set. This does not mean the job is 
903 // scheduled with a default PR trigger despite the correlation being true at the moment.
904 def static isInnerloopTestScenario(def scenario) {
905     return (scenario == 'innerloop' || scenario == 'no_tiered_compilation_innerloop')
906 }
907
908 def static isCrossGenComparisonScenario(def scenario) {
909     return (scenario == 'crossgen_comparison')
910 }
911
912 def static shouldGenerateCrossGenComparisonJob(def os, def architecture, def configuration, def scenario) {
913     assert isCrossGenComparisonScenario(scenario)
914     return ((os == 'Ubuntu' && architecture == 'arm') || (os == 'Ubuntu16.04' && architecture == 'arm64')) && (configuration == 'Checked' || configuration == 'Release')
915 }
916
917 def static getFxBranch(def branch) {
918     def fxBranch = branch
919     // Map 'dev/unix_test_workflow' to 'master' so we can test CoreFX jobs in the CoreCLR dev/unix_test_workflow
920     // branch even though CoreFX doesn't have such a branch.
921     if (branch == 'dev/unix_test_workflow') {
922         fxBranch = 'master'
923     }
924     return fxBranch
925 }
926
927 def static setJobTimeout(newJob, isPR, architecture, configuration, scenario, isBuildOnly) {
928     // 2 hours (120 minutes) is the default timeout
929     def timeout = 120
930
931     if (!isInnerloopTestScenario(scenario)) {
932         // Pri-1 test builds take a long time (see calculateBuildCommands()). So up the Pri-1 build jobs timeout.
933         timeout = 240
934     }
935
936     if (!isBuildOnly) {
937         // Note that these can only increase, never decrease, the Pri-1 timeout possibly set above.
938         if (isGCStressRelatedTesting(scenario)) {
939             timeout = 4320
940         }
941         else if (isCoreFxScenario(scenario)) {
942             timeout = 360
943         }
944         else if (isJitStressScenario(scenario)) {
945             timeout = 300
946         }
947         else if (isR2RBaselineScenario(scenario)) {
948             timeout = 240
949         }
950         else if (isLongGc(scenario)) {
951             timeout = 1440
952         }
953         else if (isJitDiff(scenario)) {
954             timeout = 240
955         }
956         else if (isGcReliabilityFramework(scenario)) {
957             timeout = 1440
958         }
959         else if (architecture == 'armem' || architecture == 'arm64') {
960             timeout = 240
961         }
962
963         if (architecture == 'arm') {
964             // ARM32 machines are particularly slow.
965             timeout += 120
966         }
967     }
968
969     if (configuration == 'Debug') {
970         // Debug runs can be very slow. Add an hour.
971         timeout += 60
972     }
973
974     // If we've changed the timeout from the default, set it in the job.
975
976     if (timeout != 120) {
977         Utilities.setJobTimeout(newJob, timeout)
978     }
979 }
980
981 def static getJobFolder(def scenario) {
982     if (isJitStressScenario(scenario) || isR2RStressScenario(scenario)) {
983         return 'jitstress'
984     }
985     if (scenario == 'illink') {
986         return 'illink'
987     }
988     return ''
989 }
990
991 def static getStressModeDisplayName(def scenario) {
992     def displayStr = ''
993     Constants.jitStressModeScenarios[scenario].each{ k, v ->
994         def prefixLength = 'COMPlus_'.length()
995         if (k.length() >= prefixLength) {
996             def modeName = k.substring(prefixLength, k.length())
997             if (displayStr != '') {
998                 // Separate multiple variables with a space.
999                 displayStr += ' '
1000             }
1001             displayStr += modeName + '=' + v
1002         }
1003     }
1004
1005     if (isCoreFxScenario(scenario)) {
1006         displayStr = ('CoreFx ' + displayStr).trim()
1007     }
1008
1009     return displayStr
1010 }
1011
1012 def static getR2RDisplayName(def scenario) {
1013     // Assume the scenario name is one from the r2rStressScenarios dict, and remove its "r2r_" prefix.
1014     def displayStr = scenario
1015     def prefixLength = 'r2r_'.length()
1016     if (displayStr.length() >= prefixLength) {
1017         displayStr = "R2R " + displayStr.substring(prefixLength, displayStr.length())
1018     } else if (scenario == 'r2r') {
1019         displayStr = "R2R"
1020     }
1021     return displayStr
1022 }
1023
1024 def static getScenarioDisplayString(def scenario) {
1025     switch (scenario) {
1026         case 'innerloop':
1027             return "Innerloop Build and Test"
1028
1029         case 'no_tiered_compilation_innerloop':
1030             def displayStr = getStressModeDisplayName(scenario)
1031             return "Innerloop Build and Test (Jit - ${displayStr})"
1032
1033         case 'corefx_innerloop':
1034             return "CoreFX Tests"
1035
1036         case 'normal':
1037             return "Build and Test"
1038
1039         case 'jitdiff':
1040             return "Jit Diff Build and Test"
1041
1042         case 'ilrt':
1043             return "IL RoundTrip Build and Test"
1044
1045         case 'longgc':
1046             return "Long-Running GC Build & Test"
1047
1048         case 'gcsimulator':
1049             return "GC Simulator"
1050
1051         case 'standalone_gc':
1052             return "Standalone GC"
1053
1054         case 'gc_reliability_framework':
1055             return "GC Reliability Framework"
1056
1057         case 'illink':
1058             return "via ILLink"
1059
1060         default:
1061             if (isJitStressScenario(scenario)) {
1062                 def displayStr = getStressModeDisplayName(scenario)
1063                 return "Build and Test (Jit - ${displayStr})"
1064             }
1065             else if (isR2RScenario(scenario)) {
1066                 def displayStr = getR2RDisplayName(scenario)
1067                 return "${displayStr} Build and Test"
1068             }
1069             else {
1070                 return "${scenario}"
1071             }
1072             break
1073     }
1074
1075     println("Unknown scenario: ${scenario}");
1076     assert false
1077 }
1078
1079 //
1080 // Functions to create an environment script.
1081 //      envScriptCreate -- initialize the script (call first)
1082 //      envScriptFinalize -- finalize the script (call last)
1083 //      envScriptSetStressModeVariables -- set stress mode variables in the env script
1084 //      envScriptAppendExistingScript -- append an existing script to the generated script
1085 //
1086 // Each script returns a string of commands. Concatenate all the strings together before
1087 // adding them to the builds commands, to make sure they get executed as one Jenkins script.
1088 //
1089
1090 // Initialize the environment setting script.
1091 def static envScriptCreate(def os, def stepScriptLocation) {
1092     def stepScript = ''
1093     if (os == 'Windows_NT') {
1094         stepScript += "echo Creating TestEnv script\r\n"
1095         stepScript += "if exist ${stepScriptLocation} del ${stepScriptLocation}\r\n"
1096
1097         // Create at least an empty script.
1098         stepScript += "echo. > ${stepScriptLocation}\r\n"
1099     }
1100     else {
1101         stepScript += "echo Creating environment setting script\n"
1102         stepScript += "echo \\#\\!/usr/bin/env bash > ${stepScriptLocation}\n"
1103     }
1104
1105     return stepScript
1106 }
1107
1108 // Generates the string for setting stress mode variables.
1109 def static envScriptSetStressModeVariables(def os, def stressModeVars, def stepScriptLocation) {
1110     def stepScript = ''
1111     if (os == 'Windows_NT') {
1112         stressModeVars.each{ k, v ->
1113             // Write out what we are writing to the script file
1114             stepScript += "echo Setting ${k}=${v}\r\n"
1115             // Write out the set itself to the script file`
1116             stepScript += "echo set ${k}=${v} >> ${stepScriptLocation}\r\n"
1117         }
1118     }
1119     else {
1120         stressModeVars.each{ k, v ->
1121             // Write out what we are writing to the script file
1122             stepScript += "echo Setting ${k}=${v}\n"
1123             // Write out the set itself to the script file`
1124             stepScript += "echo export ${k}=${v} >> ${stepScriptLocation}\n"
1125         }
1126     }
1127
1128     return stepScript
1129 }
1130
1131 // Append an existing script to an environment script.
1132 // Returns string of commands to do this.
1133 def static envScriptAppendExistingScript(def os, def appendScript, def stepScriptLocation) {
1134     assert (os == 'Windows_NT')
1135     def stepScript = ''
1136
1137     stepScript += "echo Appending ${appendScript} to ${stepScriptLocation}\r\n"
1138     stepScript += "type ${appendScript} >> ${stepScriptLocation}\r\n"
1139
1140     return stepScript
1141 }
1142
1143 // Finalize an environment setting script.
1144 // Returns string of commands to do this.
1145 def static envScriptFinalize(def os, def stepScriptLocation) {
1146     def stepScript = ''
1147
1148     if (os == 'Windows_NT') {
1149         // Display the resulting script. This is useful when looking at the output log file.
1150         stepScript += "echo Display the total script ${stepScriptLocation}\r\n"
1151         stepScript += "type ${stepScriptLocation}\r\n"
1152     }
1153     else {
1154         stepScript += "chmod +x ${stepScriptLocation}\n"
1155     }
1156
1157     return stepScript
1158 }
1159
1160 def static isNeedDocker(def architecture, def os, def isBuild) {
1161     if (isBuild) {
1162         if (architecture == 'x86' && os == 'Ubuntu') {
1163             return true
1164         }
1165         else if (architecture == 'armem') {
1166             return true
1167         }
1168         else if (architecture == 'arm') {
1169             if (os == 'Ubuntu') {
1170                 return true
1171             }
1172         }
1173         else if (architecture == 'arm64') {
1174             if (os == 'Ubuntu16.04') {
1175                 return true
1176             }
1177         }
1178     }
1179     else {
1180         if (architecture == 'x86' && os == 'Ubuntu') {
1181             return true
1182         }
1183     }
1184     return false
1185 }
1186
1187 def static getDockerImageName(def architecture, def os, def isBuild) {
1188     // We must change some docker private images to official later
1189     if (isBuild) {
1190         if (architecture == 'x86' && os == 'Ubuntu') {
1191             return "hseok82/dotnet-buildtools-prereqs:ubuntu-16.04-crossx86-ef0ac75-20175511035548"
1192         }
1193         else if (architecture == 'armem') {
1194             if (os == 'Tizen') {
1195                 return "tizendotnet/dotnet-buildtools-prereqs:ubuntu-16.04-cross-e435274-20180426002255-tizen-rootfs-5.0m1"
1196             }
1197         }
1198         else if (architecture == 'arm') {
1199             if (os == 'Ubuntu') {
1200                 return "microsoft/dotnet-buildtools-prereqs:ubuntu-14.04-cross-e435274-20180426002420"
1201             }
1202         }
1203         else if (architecture == 'arm64') {
1204             if (os == 'Ubuntu16.04') {
1205                 return "microsoft/dotnet-buildtools-prereqs:ubuntu-16.04-cross-arm64-a3ae44b-20180315221921"
1206             }
1207         }
1208     }
1209     else {
1210         if (architecture == 'x86' && os == 'Ubuntu') {
1211             return "hseok82/dotnet-buildtools-prereqs:ubuntu1604_x86_test"
1212         }
1213     }
1214     println("Unknown architecture to use docker: ${architecture} ${os}");
1215     assert false
1216 }
1217
1218 def static getTestArtifactsTgzFileName(def osGroup, def architecture, def configuration) {
1219     return "bin-tests-${osGroup}.${architecture}.${configuration}.tgz"
1220 }
1221
1222 // We have a limited amount of some hardware. For these, scale back the periodic testing we do,
1223 // and only allowing using this hardware in some specific branches.
1224 def static jobRequiresLimitedHardware(def architecture, def os) {
1225     if (architecture == 'arm') {
1226         // arm Windows and Linux hardware is limited.
1227         return true
1228     }
1229     else if (architecture == 'arm64') {
1230         // arm64 Windows and Linux hardware is limited.
1231         return true
1232     }
1233     else {
1234         return false
1235     }
1236 }
1237
1238 // Calculates the name of the build job based on some typical parameters.
1239 //
1240 def static getJobName(def configuration, def architecture, def os, def scenario, def isBuildOnly) {
1241     // If the architecture is x64, do not add that info into the build name.
1242     // Need to change around some systems and other builds to pick up the right builds
1243     // to do that.
1244
1245     def suffix = scenario != 'normal' ? "_${scenario}" : '';
1246     if (isBuildOnly) {
1247         suffix += '_bld'
1248     }
1249     def baseName = ''
1250     switch (architecture) {
1251         case 'x64':
1252             if (scenario == 'normal') {
1253                 // For now we leave x64 off of the name for compatibility with other jobs
1254                 baseName = configuration.toLowerCase() + '_' + os.toLowerCase()
1255             }
1256             else if (scenario == 'formatting') {
1257                 // we don't care about the configuration for the formatting job. It runs all configs
1258                 baseName = architecture.toLowerCase() + '_' + os.toLowerCase()
1259             }
1260             else {
1261                 baseName = architecture.toLowerCase() + '_' + configuration.toLowerCase() + '_' + os.toLowerCase()
1262             }
1263             break
1264         case 'armem':
1265             // These are cross builds
1266             assert os == 'Tizen'
1267             baseName = 'armel_cross_' + configuration.toLowerCase() + '_' + os.toLowerCase()
1268             break
1269         case 'arm':
1270         case 'arm64':
1271             // These are cross builds
1272             baseName = architecture.toLowerCase() + '_cross_' + configuration.toLowerCase() + '_' + os.toLowerCase()
1273             break
1274         case 'x86':
1275             baseName = architecture.toLowerCase() + '_' + configuration.toLowerCase() + '_' + os.toLowerCase()
1276             break
1277         default:
1278             println("Unknown architecture: ${architecture}");
1279             assert false
1280             break
1281     }
1282
1283     return baseName + suffix
1284 }
1285
1286 def static addNonPRTriggers(def job, def branch, def isPR, def architecture, def os, def configuration, def scenario, def isFlowJob, def isWindowsBuildOnlyJob, def bidailyCrossList) {
1287
1288     // The dev/unix_test_workflow branch is used for Jenkins CI testing. We generally do not need any non-PR
1289     // triggers in the branch, because that would use machine resources unnecessarily.
1290     if (branch == 'dev/unix_test_workflow') {
1291         return
1292     }
1293
1294     // Limited hardware is restricted for non-PR triggers to certain branches.
1295     if (jobRequiresLimitedHardware(architecture, os) && (!(branch in Constants.LimitedHardwareBranches))) {
1296         return
1297     }
1298
1299     // Ubuntu x86 CI jobs are failing. Disable non-PR triggered jobs to avoid these constant failures
1300     // until this is fixed. Tracked by https://github.com/dotnet/coreclr/issues/19003.
1301     if (architecture == 'x86' && os == 'Ubuntu') {
1302         return
1303     }
1304
1305     def isNormalOrInnerloop = (scenario == "normal" || scenario == "innerloop")
1306
1307     // Check scenario.
1308     switch (scenario) {
1309         case 'crossgen_comparison':
1310             if (isFlowJob && ((os == 'Ubuntu' && architecture == 'arm') || (os == 'Ubuntu16.04' && architecture == 'arm64')) && (configuration == 'Checked' || configuration == 'Release')) {
1311                 addPeriodicTriggerHelper(job, '@daily')
1312             }
1313             break
1314
1315         case 'pmi_asm_diffs':
1316             // No non-PR triggers for now.
1317             break
1318
1319         case 'normal':
1320             switch (architecture) {
1321                 case 'x64':
1322                 case 'x86':
1323                     if (isFlowJob && architecture == 'x86' && os == 'Ubuntu') {
1324                         addPeriodicTriggerHelper(job, '@daily')
1325                     }
1326                     else if (isFlowJob || os == 'Windows_NT' || (architecture == 'x64' && !(os in Constants.crossList))) {
1327                         addGithubPushTriggerHelper(job)
1328                     }
1329                     break
1330                 case 'arm64':
1331                     if (os == 'Windows_NT') {
1332                         if (isFlowJob || (isNormalOrInnerloop && (configuration == 'Debug'))) {
1333                             // We would normally want a per-push trigger, but with limited hardware we can't keep up.
1334                             // Do the builds daily.
1335                             addPeriodicTriggerHelper(job, '@daily')
1336                         }
1337                     }
1338                     else {
1339                         // Only the flow jobs get push triggers; the build and test jobs are triggered by the flow job.
1340                         if (isFlowJob) {
1341                             addPeriodicTriggerHelper(job, '@daily')
1342                         }
1343                     }
1344                     break
1345                 case 'arm':
1346                     if (os == 'Windows_NT') {
1347                         if (isFlowJob || (isNormalOrInnerloop && (configuration == 'Debug'))) {
1348                             // We would normally want a push trigger, but with limited hardware we can't keep up.
1349                             // Do the builds daily.
1350                             addPeriodicTriggerHelper(job, '@daily')
1351                         }
1352                     }
1353                     else {
1354                         assert os == 'Ubuntu'
1355                         // Only the flow jobs get push triggers; the build and test jobs are triggered by the flow job.
1356                         if (isFlowJob) {
1357                             // Currently no push triggers, with limited arm Linux hardware.
1358                             // TODO: If we have enough machine capacity, add some arm Linux push triggers.
1359                             addPeriodicTriggerHelper(job, '@daily')
1360                         }
1361                     }
1362                     break
1363                 case 'armem':
1364                     addGithubPushTriggerHelper(job)
1365                     break
1366                 default:
1367                     println("Unknown architecture: ${architecture}");
1368                     assert false
1369                     break
1370             }
1371             break
1372         case 'r2r':
1373             assert !(os in bidailyCrossList)
1374             // r2r gets a push trigger for checked/release
1375             if (configuration == 'Checked' || configuration == 'Release') {
1376                 if (architecture == 'x64' && os != 'OSX10.12') {
1377                     //Flow jobs should be Windows, Ubuntu, OSX0.12, or CentOS
1378                     if (isFlowJob || os == 'Windows_NT') {
1379                         addGithubPushTriggerHelper(job)
1380                     }
1381                 // OSX10.12 r2r jobs should only run every 12 hours, not daily.
1382                 } else if (architecture == 'x64' && os == 'OSX10.12'){
1383                     if (isFlowJob) {
1384                         addPeriodicTriggerHelper(job, 'H H/12 * * *')
1385                     }
1386                 }
1387                 // For x86, only add per-commit jobs for Windows
1388                 else if (architecture == 'x86') {
1389                     if (os == 'Windows_NT') {
1390                         addGithubPushTriggerHelper(job)
1391                     }
1392                 }
1393                 // arm r2r jobs should only run weekly.
1394                 else if (architecture == 'arm') {
1395                     if (isFlowJob) {
1396                         addPeriodicTriggerHelper(job, '@weekly')
1397                     }
1398                 }
1399                 // arm64 r2r jobs should only run weekly.
1400                 else if (architecture == 'arm64') {
1401                     if (isFlowJob) {
1402                         addPeriodicTriggerHelper(job, '@weekly')
1403                     }
1404                 }
1405             }
1406             break
1407         case 'r2r_jitstress1':
1408         case 'r2r_jitstress2':
1409         case 'r2r_jitstress1_tiered':
1410         case 'r2r_jitstress2_tiered':
1411         case 'r2r_jitstressregs1':
1412         case 'r2r_jitstressregs2':
1413         case 'r2r_jitstressregs3':
1414         case 'r2r_jitstressregs4':
1415         case 'r2r_jitstressregs8':
1416         case 'r2r_jitstressregs0x10':
1417         case 'r2r_jitstressregs0x80':
1418         case 'r2r_jitstressregs0x1000':
1419         case 'r2r_jitminopts':
1420         case 'r2r_jitforcerelocs':
1421         case 'r2r_gcstress15':
1422         case 'r2r_no_tiered_compilation':
1423             assert !(os in bidailyCrossList)
1424
1425             // GCStress=C is currently not supported on OS X
1426             if (os == 'OSX10.12' && isGCStressRelatedTesting(scenario)) {
1427                 break
1428             }
1429
1430             if (configuration == 'Checked' || configuration == 'Release') {
1431                 if (architecture == 'x64') {
1432                     //Flow jobs should be Windows, Ubuntu, OSX10.12, or CentOS
1433                     if (isFlowJob || os == 'Windows_NT') {
1434                         addPeriodicTriggerHelper(job, 'H H * * 3,6') // some time every Wednesday and Saturday
1435                     }
1436                 }
1437                 // For x86, only add periodic jobs for Windows
1438                 else if (architecture == 'x86') {
1439                     if (os == 'Windows_NT') {
1440                         addPeriodicTriggerHelper(job, 'H H * * 3,6') // some time every Wednesday and Saturday
1441                     }
1442                 }
1443                 else if (architecture == 'arm') {
1444                     if (isFlowJob) {
1445                         addPeriodicTriggerHelper(job, '@weekly')
1446                     }
1447                 }
1448                 else if (architecture == 'arm64') {
1449                     if (isFlowJob) {
1450                         addPeriodicTriggerHelper(job, '@weekly')
1451                     }
1452                 }
1453             }
1454             break
1455         case 'longgc':
1456             assert (os == 'Ubuntu' || os == 'Windows_NT' || os == 'OSX10.12')
1457             assert configuration == 'Release'
1458             assert architecture == 'x64'
1459             addPeriodicTriggerHelper(job, '@daily')
1460             // TODO: Add once external email sending is available again
1461             // addEmailPublisher(job, 'dotnetgctests@microsoft.com')
1462             break
1463         case 'gcsimulator':
1464             assert (os == 'Ubuntu' || os == 'Windows_NT' || os == 'OSX10.12')
1465             assert configuration == 'Release'
1466             assert architecture == 'x64'
1467             addPeriodicTriggerHelper(job, 'H H * * 3,6') // some time every Wednesday and Saturday
1468             // TODO: Add once external email sending is available again
1469             // addEmailPublisher(job, 'dotnetgctests@microsoft.com')
1470             break
1471         case 'standalone_gc':
1472             assert (os == 'Ubuntu' || os == 'Windows_NT' || os == 'OSX10.12')
1473             assert (configuration == 'Release' || configuration == 'Checked')
1474             // TODO: Add once external email sending is available again
1475             // addEmailPublisher(job, 'dotnetgctests@microsoft.com')
1476             addPeriodicTriggerHelper(job, '@daily')
1477             break
1478         case 'gc_reliability_framework':
1479             assert (os == 'Ubuntu' || os == 'Windows_NT' || os == 'OSX10.12')
1480             assert (configuration == 'Release' || configuration == 'Checked')
1481             // Only triggered by phrase.
1482             break
1483         case 'ilrt':
1484             assert !(os in bidailyCrossList)
1485             // ILASM/ILDASM roundtrip one gets a daily build, and only for release
1486             if (architecture == 'x64' && configuration == 'Release') {
1487                 if (isFlowJob || os == 'Windows_NT') {
1488                     addPeriodicTriggerHelper(job, '@daily')
1489                 }
1490             }
1491             break
1492         case 'jitdiff':
1493             assert (os == 'Ubuntu' || os == 'Windows_NT' || os == 'OSX10.12')
1494             assert configuration == 'Checked'
1495             assert (architecture == 'x64' || architecture == 'x86')
1496             addGithubPushTriggerHelper(job)
1497             break
1498         case 'formatting':
1499             assert (os == 'Windows_NT' || os == "Ubuntu")
1500             assert architecture == 'x64'
1501             addGithubPushTriggerHelper(job)
1502             break
1503         case 'jitstressregs1':
1504         case 'jitstressregs2':
1505         case 'jitstressregs3':
1506         case 'jitstressregs4':
1507         case 'jitstressregs8':
1508         case 'jitstressregs0x10':
1509         case 'jitstressregs0x80':
1510         case 'jitstressregs0x1000':
1511         case 'minopts':
1512         case 'tieredcompilation':
1513         case 'no_tiered_compilation':
1514         case 'forcerelocs':
1515         case 'jitstress1':
1516         case 'jitstress2':
1517         case 'jitstress1_tiered':
1518         case 'jitstress2_tiered':
1519         case 'jitstress2_jitstressregs1':
1520         case 'jitstress2_jitstressregs2':
1521         case 'jitstress2_jitstressregs3':
1522         case 'jitstress2_jitstressregs4':
1523         case 'jitstress2_jitstressregs8':
1524         case 'jitstress2_jitstressregs0x10':
1525         case 'jitstress2_jitstressregs0x80':
1526         case 'jitstress2_jitstressregs0x1000':
1527         case 'tailcallstress':
1528         case 'jitsse2only':
1529         case 'jitnosimd':
1530         case 'jitnox86hwintrinsic':
1531         case 'jitincompletehwintrinsic':
1532         case 'jitx86hwintrinsicnoavx':
1533         case 'jitx86hwintrinsicnoavx2':
1534         case 'jitx86hwintrinsicnosimd':
1535         case 'corefx_baseline':
1536         case 'corefx_minopts':
1537         case 'corefx_tieredcompilation':
1538         case 'corefx_jitstress1':
1539         case 'corefx_jitstress2':
1540         case 'corefx_jitstressregs1':
1541         case 'corefx_jitstressregs2':
1542         case 'corefx_jitstressregs3':
1543         case 'corefx_jitstressregs4':
1544         case 'corefx_jitstressregs8':
1545         case 'corefx_jitstressregs0x10':
1546         case 'corefx_jitstressregs0x80':
1547         case 'corefx_jitstressregs0x1000':
1548         case 'zapdisable':
1549             if (os == 'CentOS7.1') {
1550                 break
1551             }
1552             if (os in bidailyCrossList) {
1553                 break
1554             }
1555             // ARM corefx testing uses non-flow jobs to provide the configuration-specific
1556             // build for the flow job. We don't need cron jobs for these. Note that the
1557             // Windows ARM jobs depend on a Windows "build only" job that exits the trigger
1558             // function very early, so only non-Windows gets here.
1559             if ((architecture == 'arm') && isCoreFxScenario(scenario) && !isFlowJob) {
1560                 break
1561             }
1562             if ((architecture == 'arm64') && isCoreFxScenario(scenario) && !isFlowJob) {
1563                 break
1564             }
1565             if (jobRequiresLimitedHardware(architecture, os)) {
1566                 if ((architecture == 'arm64') && (os == 'Ubuntu16.04')) {
1567                     // These jobs are very fast on Linux/arm64 hardware, so run them daily.
1568                     addPeriodicTriggerHelper(job, '@daily')
1569                 }
1570                 else {
1571                     addPeriodicTriggerHelper(job, '@weekly')
1572                 }
1573             }
1574             else {
1575                 addPeriodicTriggerHelper(job, '@daily')
1576             }
1577             break
1578         case 'heapverify1':
1579         case 'gcstress0x3':
1580             if (os == 'CentOS7.1') {
1581                 break
1582             }
1583             if (os in bidailyCrossList) {
1584                 break
1585             }
1586             addPeriodicTriggerHelper(job, '@weekly')
1587             break
1588         case 'gcstress0xc':
1589         case 'gcstress0xc_zapdisable':
1590         case 'gcstress0xc_zapdisable_jitstress2':
1591         case 'gcstress0xc_zapdisable_heapverify1':
1592         case 'gcstress0xc_jitstress1':
1593         case 'gcstress0xc_jitstress2':
1594         case 'gcstress0xc_minopts_heapverify1':
1595             if (os == 'OSX10.12') {
1596                 // GCStress=C is currently not supported on OS X
1597                 break
1598             }
1599             if (os == 'CentOS7.1') {
1600                 break
1601             }
1602             if (os in bidailyCrossList) {
1603                 break
1604             }
1605             addPeriodicTriggerHelper(job, '@weekly')
1606             break
1607
1608         case 'illink':
1609             // Testing on other operating systems TBD
1610             assert (os == 'Windows_NT' || os == 'Ubuntu')
1611             if (architecture == 'x64' || architecture == 'x86') {
1612                 if (configuration == 'Checked') {
1613                     addPeriodicTriggerHelper(job, '@daily')
1614                 }
1615             }
1616             break
1617
1618         default:
1619             println("Unknown scenario: ${scenario}");
1620             assert false
1621             break
1622     }
1623     return
1624 }
1625
1626 // **************************
1627 // Define the basic inner loop builds for PR and commit.  This is basically just the set
1628 // of coreclr builds over linux/osx 10.12/windows and debug/release/checked.  In addition, the windows
1629 // builds will do a couple extra steps.
1630 // **************************
1631
1632 // Adds a trigger for the PR build if one is needed.  If isFlowJob is true, then this is the
1633 // flow job that rolls up the build and test for non-windows OS's.  // If the job is a windows build only job,
1634 // it's just used for internal builds
1635 // If you add a job with a trigger phrase, please add that phrase to coreclr/Documentation/project-docs/ci-trigger-phrases.md
1636 def static addTriggers(def job, def branch, def isPR, def architecture, def os, def configuration, def scenario, def isFlowJob, def isWindowsBuildOnlyJob) {
1637     def isNormalOrInnerloop = (scenario == "normal" || scenario == "innerloop")
1638     
1639     if (isWindowsBuildOnlyJob) {
1640         return
1641     }
1642
1643     def bidailyCrossList = ['RHEL7.2', 'Debian8.4']
1644     // Non pull request builds.
1645     if (!isPR) {
1646         addNonPRTriggers(job, branch, isPR, architecture, os, configuration, scenario, isFlowJob, isWindowsBuildOnlyJob, bidailyCrossList)
1647         return
1648     }
1649
1650     def arm64Users = [
1651         'adityamandaleeka',
1652         'AndyAyersMS',
1653         'briansull',
1654         'BruceForstall',
1655         'CarolEidt',
1656         'davidwrighton',
1657         'echesakovMSFT',
1658         'erozenfeld',
1659         'janvorli',
1660         'jashook',
1661         'pgodeq',
1662         'RussKeldorph',
1663         'sandreenko',
1664         'sdmaclea',
1665         'swaroop-sridhar',
1666         'jkotas',
1667         'markwilkie',
1668         'weshaggard',
1669         'tannergooding'
1670     ]
1671
1672     // Pull request builds.  Generally these fall into two categories: default triggers and on-demand triggers
1673     // We generally only have a distinct set of default triggers but a bunch of on-demand ones.
1674
1675     def contextString = ""
1676     def triggerString = ""
1677     def needsTrigger = true
1678     def isDefaultTrigger = false
1679     def isArm64PrivateJob = false
1680     def scenarioString = ""
1681
1682     // Set up default context string and trigger phrases. This is overridden in places, sometimes just to keep
1683     // the existing non-standard descriptions and phrases. In some cases, the scenarios are asymmetric, as for
1684     // some jobs where the Debug configuration just does builds, no tests.
1685     //
1686     // Some configurations, like arm32/arm64, always use the exact scenario name as part of the context string.
1687     // This makes it possible to copy/paste the displayed context string as "@dotnet-bot test <context-string>"
1688     // to invoke the trigger. Any "fancy" context string makes that impossible, requiring the user to either 
1689     // remember the mapping from context string to trigger string, or use "@dotnet-bot help" to look it up.
1690
1691     if (architecture == 'armem') {
1692         assert os == 'Tizen'
1693         architecture = 'armel'
1694     }
1695
1696     switch (architecture) {
1697         case 'armel':
1698         case 'arm':
1699         case 'arm64':
1700             contextString = "${os} ${architecture} Cross ${configuration}"
1701             triggerString = "(?i).*test\\W+${os}\\W+${architecture}\\W+Cross\\W+${configuration}"
1702
1703             if (scenario == 'innerloop') {
1704                 contextString += " Innerloop"
1705                 triggerString += "\\W+Innerloop"
1706             }
1707             else {
1708                 contextString += " ${scenario}"
1709                 triggerString += "\\W+${scenario}"
1710             }
1711
1712             if (scenario == 'pmi_asm_diffs') {
1713                 // Don't add the "Build and Test" part
1714             }
1715             else if (configuration == 'Debug') {
1716                 contextString += " Build"
1717                 triggerString += "\\W+Build"
1718             }
1719             else {
1720                 contextString += " Build and Test"
1721                 triggerString += "\\W+Build and Test"
1722             }
1723
1724             triggerString += ".*"
1725             break
1726
1727         default:
1728             scenarioString = getScenarioDisplayString(scenario)
1729             contextString = "${os} ${architecture} ${configuration} ${scenarioString}"
1730             triggerString = "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}"
1731
1732             switch (scenario) {
1733                 case 'normal':
1734                     triggerString += "\\W+Build and Test.*"
1735                     break
1736
1737                 case 'corefx_innerloop': // maintain this asymmetry
1738                     triggerString += "\\W+CoreFX Tests.*"
1739                     break
1740
1741                 default:
1742                     triggerString += "\\W+${scenario}.*"
1743                     break
1744             }
1745
1746             triggerString += ".*"
1747             break
1748     }
1749
1750     // Now determine what kind of trigger this job needs, if any. Any job should be triggerable, except for
1751     // non-flow jobs that are only used as part of flow jobs.
1752
1753     switch (architecture) {
1754         case 'x64': // editor brace matching: {
1755             if (scenario == 'formatting') {
1756                 assert configuration == 'Checked'
1757                 if (os == 'Windows_NT' || os == 'Ubuntu') {
1758                     isDefaultTrigger = true
1759                     contextString = "${os} ${architecture} Formatting"
1760                 }
1761                 break
1762             }
1763
1764             if (scenario == 'pmi_asm_diffs') {
1765                 // Everything is already set.
1766                 // No default triggers.
1767                 break
1768             }
1769
1770             switch (os) {
1771                 // OpenSUSE, Debian & RedHat get trigger phrases for pri 0 build, and pri 1 build & test
1772                 case 'Debian8.4':
1773                 case 'RHEL7.2':
1774                     if (scenario == 'innerloop') {
1775                         assert !isFlowJob
1776                         contextString = "${os} ${architecture} ${configuration} Innerloop Build"
1777                         isDefaultTrigger = true
1778                         break
1779                     }
1780
1781                     // fall through
1782
1783                 case 'Fedora24':
1784                 case 'Ubuntu16.04':
1785                 case 'Ubuntu16.10':
1786                     assert !isFlowJob
1787                     assert scenario != 'innerloop'
1788                     contextString = "${os} ${architecture} ${configuration} Build"
1789                     triggerString = "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+Build.*"
1790                     break
1791
1792                 case 'Ubuntu':
1793                     if (scenario == 'illink') {
1794                         break
1795                     }
1796                     else if (scenario == 'corefx_innerloop') {
1797                         if (configuration == 'Checked') {
1798                             isDefaultTrigger = true
1799                         }
1800                         break
1801                     }
1802
1803                     // fall through
1804
1805                 case 'OSX10.12':
1806                     // Triggers on the non-flow jobs aren't necessary here
1807                     // Corefx testing uses non-flow jobs.
1808                     if (!isFlowJob && !isCoreFxScenario(scenario)) {
1809                         needsTrigger = false
1810                         break
1811                     }
1812                     switch (scenario) {
1813                         case 'innerloop':
1814                             isDefaultTrigger = true
1815                             break
1816
1817                         case 'no_tiered_compilation_innerloop':
1818                             if (os == 'Ubuntu') {
1819                                 isDefaultTrigger = true
1820                             }
1821                             break
1822
1823                         default:
1824                             break
1825                     }
1826                     break
1827
1828                 case 'CentOS7.1':
1829                     switch (scenario) {
1830                         case 'innerloop':
1831                             // CentOS uses checked for default PR tests while debug is build only
1832                             if (configuration == 'Debug') {
1833                                 isDefaultTrigger = true
1834                                 contextString = "${os} ${architecture} ${configuration} Innerloop Build"
1835                                 break
1836                             }
1837                             
1838                             // Make sure this is a flow job to get build and test.
1839                             if (!isFlowJob) {
1840                                 needsTrigger = false
1841                                 break
1842                             }
1843
1844                             if (configuration == 'Checked') {
1845                                 assert job.name.contains("flow")
1846                                 isDefaultTrigger = true
1847                                 contextString = "${os} ${architecture} ${configuration} Innerloop Build and Test"
1848                             }
1849                             break
1850
1851                         case 'normal':
1852                             // Make sure this is a flow job to get build and test.
1853                             if (!isFlowJob) {
1854                                 needsTrigger = false
1855                                 break
1856                             }
1857                             break
1858
1859                         default:
1860                             break
1861                     }
1862                     break
1863
1864                 case 'Windows_NT':
1865                     switch (scenario) {
1866                         case 'innerloop':
1867                         case 'no_tiered_compilation_innerloop':
1868                             isDefaultTrigger = true
1869                             break
1870
1871                         case 'corefx_innerloop':
1872                             if (configuration == 'Checked' || configuration == 'Release') {
1873                                 isDefaultTrigger = true
1874                             }
1875                             break
1876
1877                         default:
1878                             break
1879                     }
1880                     break
1881
1882                 default:
1883                     println("Unknown os: ${os}");
1884                     assert false
1885                     break
1886
1887             } // switch (os)
1888
1889             break
1890         // editor brace matching: }
1891
1892         case 'armel': // editor brace matching: {
1893             job.with {
1894                 publishers {
1895                     azureVMAgentPostBuildAction {
1896                         agentPostBuildAction('Delete agent if the build was not successful (when idle).')
1897                     }
1898                 }
1899             }
1900
1901             switch (os) {
1902                 case 'Tizen':
1903                     if (scenario == 'innerloop') {
1904                         if (configuration == 'Checked') {
1905                             isDefaultTrigger = true
1906                         }
1907                     }
1908                     break
1909             }
1910
1911             break
1912         // editor brace matching: }
1913
1914         case 'arm':
1915         case 'arm64': // editor brace matching: {
1916
1917             switch (os) {
1918                 case 'Ubuntu':
1919                 case 'Ubuntu16.04':
1920
1921                     // Triggers on the non-flow jobs aren't necessary
1922                     if (!isFlowJob) {
1923                         needsTrigger = false
1924                         break
1925                     }
1926                     if (os == 'Ubuntu' && architecture == 'arm') {
1927                         switch (scenario) {
1928                             case 'innerloop':
1929                             case 'no_tiered_compilation_innerloop':
1930                                 if (configuration == 'Checked') {
1931                                     isDefaultTrigger = true
1932                                 }
1933                                 break
1934                              case 'crossgen_comparison':
1935                                 if (configuration == 'Checked' || configuration == 'Release') {
1936                                     isDefaultTrigger = true
1937                                 }
1938                                 break
1939                         }
1940                     }
1941                     break
1942
1943                 case 'Windows_NT':
1944                     assert isArmWindowsScenario(scenario)
1945
1946                     // For Debug normal/innerloop scenario, we don't do test runs, so we don't use flow jobs. That means we need a trigger for
1947                     // the non-flow Build job. All others need a trigger on the flow job.
1948                     def needsFlowJobTrigger = !(isNormalOrInnerloop && (configuration == 'Debug'))
1949                     if (isFlowJob != needsFlowJobTrigger) {
1950                         needsTrigger = false
1951                         break
1952                     }
1953
1954                     switch (scenario) {
1955                         case 'innerloop':
1956                             if (configuration == 'Checked') {
1957                                 isDefaultTrigger = true
1958                                 isArm64PrivateJob = true
1959                             }
1960                             break
1961                         default:
1962                             isArm64PrivateJob = true
1963                             break
1964                     }
1965                     break
1966                 default:
1967                     println("NYI os: ${os}");
1968                     assert false
1969                     break
1970             }
1971             break
1972
1973         // editor brace matching: }
1974         case 'x86': // editor brace matching: {
1975             assert ((os == 'Windows_NT') || ((os == 'Ubuntu') && isNormalOrInnerloop))
1976             if (os == 'Ubuntu') {
1977                 // Triggers on the non-flow jobs aren't necessary here
1978                 if (!isFlowJob) {
1979                     needsTrigger = false
1980                     break
1981                 }
1982                 
1983                 // on-demand only for ubuntu x86
1984                 contextString = "${os} ${architecture} ${configuration} Build"
1985                 triggerString = "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}.*"
1986                 break
1987             }
1988             switch (scenario) {
1989                 case 'innerloop':
1990                 case 'no_tiered_compilation_innerloop':
1991                     isDefaultTrigger = true
1992                     break
1993                 default:
1994                     break
1995             }
1996             break
1997
1998         // editor brace matching: }
1999
2000         default:
2001             println("Unknown architecture: ${architecture}");
2002             assert false
2003             break
2004     }
2005
2006     if (needsTrigger) {
2007         if (isArm64PrivateJob) {
2008             if (isDefaultTrigger) {
2009                 Utilities.addDefaultPrivateGithubPRTriggerForBranch(job, branch, contextString, null, arm64Users)
2010             }
2011             else {
2012                 Utilities.addPrivateGithubPRTriggerForBranch(job, branch, contextString, triggerString, null, arm64Users)
2013             }
2014         }
2015         else {
2016             if (isDefaultTrigger) {
2017                 Utilities.addGithubPRTriggerForBranch(job, branch, contextString)
2018             }
2019             else {
2020                 Utilities.addGithubPRTriggerForBranch(job, branch, contextString, triggerString)
2021             }
2022         }
2023     }
2024 }
2025
2026 def static calculateBuildCommands(def newJob, def scenario, def branch, def isPR, def architecture, def configuration, def os, def isBuildOnly) {
2027     def buildCommands = []
2028     def osGroup = getOSGroup(os)
2029     def lowerConfiguration = configuration.toLowerCase()
2030
2031     // Which set of tests to build? Innerloop tests build Pri-0.
2032     // Currently, we only generate asm diffs on Pri-0 tests, if we generate asm diffs on tests at all.
2033     // CoreFX testing skipts building tests altogether (done below).
2034     // All other scenarios build Pri-1 tests.
2035     def priority = '1'
2036     if (isInnerloopTestScenario(scenario)) {
2037         priority = '0'
2038     }
2039
2040     def doCoreFxTesting = isCoreFxScenario(scenario)
2041
2042     def buildCoreclrTests = true
2043     if (doCoreFxTesting || (scenario == 'pmi_asm_diffs')) {
2044         // These scenarios don't need the coreclr tests build.
2045         buildCoreclrTests = false
2046     }
2047
2048     // Calculate the build steps, archival, and xunit results
2049     switch (os) {
2050         case 'Windows_NT': // editor brace matching: {
2051             switch (architecture) {
2052                 case 'x64':
2053                 case 'x86':
2054                     def arch = architecture
2055                     def buildOpts = ''
2056
2057                     if (scenario == 'formatting') {
2058                         buildCommands += "python -u tests\\scripts\\format.py -c %WORKSPACE% -o Windows_NT -a ${arch}"
2059                         Utilities.addArchival(newJob, "format.patch", "", true, false)
2060                         break
2061                     }
2062
2063                     if (scenario == 'illink') {
2064                         buildCommands += "tests\\scripts\\build_illink.cmd clone ${arch}"
2065                     }
2066
2067                     // If it is a release build for Windows, ensure PGO is used, else fail the build.
2068                     if ((lowerConfiguration == 'release') &&
2069                         (scenario in Constants.basicScenarios)) {
2070
2071                         buildOpts += ' -enforcepgo'
2072                     }
2073
2074                     if (buildCoreclrTests) {
2075                         buildOpts += " -priority=${priority}"
2076                     } else {
2077                         buildOpts += ' skiptests';
2078                     }
2079
2080                     // Set __TestIntermediateDir to something short. If __TestIntermediateDir is already set, build-test.cmd will
2081                     // output test binaries to that directory. If it is not set, the binaries are sent to a default directory whose name is about
2082                     // 35 characters long.
2083
2084                     buildCommands += "set __TestIntermediateDir=int&&build.cmd ${lowerConfiguration} ${arch} ${buildOpts}"
2085
2086                     if (scenario == 'pmi_asm_diffs') {
2087                         // Now, generate the layout. We don't have any tests, but we need to restore the packages before calling runtest.cmd.
2088                         // Call build-test.cmd to do this. It will do a little more than we need, but that's ok.
2089                         buildCommands += "build-test.cmd ${lowerConfiguration} ${arch} skipmanaged skipnative"
2090                         buildCommands += "tests\\runtest.cmd ${lowerConfiguration} ${arch} GenerateLayoutOnly"
2091
2092                         // TODO: Add -target_branch and -commit_hash arguments based on GitHub variables.
2093                         buildCommands += "python -u %WORKSPACE%\\tests\\scripts\\run-pmi-diffs.py -arch ${arch} -ci_arch ${architecture} -build_type ${configuration}"
2094
2095                         // ZIP up the asm
2096                         buildCommands += "powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::CreateFromDirectory('_\\pmi\\asm', '.\\dasm.${os}.${architecture}.${configuration}.zip')\"";
2097
2098                         // Archive the asm
2099                         Utilities.addArchival(newJob, "dasm.${os}.${architecture}.${configuration}.zip")
2100                         break
2101                     }
2102
2103                     if (!isBuildOnly) {
2104                         def runtestArguments = ''
2105                         def testOpts = 'collectdumps'
2106
2107                         if (isR2RScenario(scenario)) {
2108
2109                             // If this is a ReadyToRun scenario, pass 'crossgen'
2110                             // to cause framework assemblies to be crossgen'ed. Pass 'runcrossgentests'
2111                             // to cause the tests to be crossgen'ed.
2112
2113                             testOpts += ' crossgen runcrossgentests'
2114                         }
2115                         else if (scenario == 'jitdiff') {
2116                             testOpts += ' jitdisasm crossgen'
2117                         }
2118                         else if (scenario == 'ilrt') {
2119                             testOpts += ' ilasmroundtrip'
2120                         }
2121                         else if (isLongGc(scenario)) {
2122                             testOpts += " ${scenario} sequential"
2123                         }
2124                         else if (scenario == 'standalone_gc') {
2125                             testOpts += ' gcname clrgc.dll'
2126                         }
2127                         else if (scenario == 'illink') {
2128                             testOpts += " link %WORKSPACE%\\linker\\linker\\bin\\netcore_Release\\netcoreapp2.0\\win10-${arch}\\publish\\illink.exe"
2129                         }
2130
2131                         // Default per-test timeout is 10 minutes. For stress modes and Debug scenarios, increase this
2132                         // to 30 minutes (30 * 60 * 1000 = 180000). The "timeout" argument to runtest.cmd sets this, by
2133                         // taking a timeout value in milliseconds. (Note that it sets the __TestTimeout environment variable,
2134                         // which is read by the xunit harness.)
2135                         if (isJitStressScenario(scenario) || isR2RStressScenario(scenario) || (lowerConfiguration == 'debug'))
2136                         {
2137                             def timeout = 1800000
2138                             testOpts += " timeout ${timeout}"
2139                         }
2140
2141                         // If we are running a stress mode, we should write out the set of key
2142                         // value env pairs to a file at this point and then we'll pass that to runtest.cmd
2143
2144                         def envScriptPath = ''
2145                         if (isJitStressScenario(scenario) || isR2RStressScenario(scenario)) {
2146                             def buildCommandsStr = ''
2147                             envScriptPath = "%WORKSPACE%\\SetStressModes.bat"
2148                             buildCommandsStr += envScriptCreate(os, envScriptPath)
2149
2150                             if (isJitStressScenario(scenario)) {
2151                                 buildCommandsStr += envScriptSetStressModeVariables(os, Constants.jitStressModeScenarios[scenario], envScriptPath)
2152                             }
2153                             else if (isR2RStressScenario(scenario)) {
2154                                 buildCommandsStr += envScriptSetStressModeVariables(os, Constants.r2rStressScenarios[scenario], envScriptPath)
2155                             }
2156
2157                             envScriptFinalize(os, envScriptPath)
2158
2159                             // Note that buildCommands is an array of individually executed commands; we want all the commands used to 
2160                             // create the SetStressModes.bat script to be executed together, hence we accumulate them as strings
2161                             // into a single script.
2162                             buildCommands += buildCommandsStr
2163                         }
2164                         if (envScriptPath != '') {
2165                             testOpts += " TestEnv ${envScriptPath}"
2166                         }
2167
2168                         runtestArguments = "${lowerConfiguration} ${arch} ${testOpts}"
2169
2170                         if (doCoreFxTesting) {
2171                             if (scenario == 'corefx_innerloop') {
2172                                 // Create CORE_ROOT and testhost
2173                                 buildCommands += "build-test.cmd ${lowerConfiguration} ${arch} buildtesthostonly"                                
2174                                 buildCommands += "tests\\runtest.cmd ${runtestArguments} CoreFXTestsAll"
2175
2176                                 // Archive and process (only) the test results
2177                                 Utilities.addArchival(newJob, "bin/Logs/**/testResults.xml")
2178                                 Utilities.addXUnitDotNETResults(newJob, "bin/Logs/**/testResults.xml")
2179                             }
2180                             else {
2181                                 def workspaceRelativeFxRoot = "_/fx"
2182                                 def absoluteFxRoot = "%WORKSPACE%\\_\\fx"
2183                                 def fxBranch = getFxBranch(branch)
2184
2185                                 buildCommands += "python -u %WORKSPACE%\\tests\\scripts\\run-corefx-tests.py -arch ${arch} -ci_arch ${architecture} -build_type ${configuration} -fx_root ${absoluteFxRoot} -fx_branch ${fxBranch} -env_script ${envScriptPath}"
2186
2187                                 // Archive and process (only) the test results
2188                                 Utilities.addArchival(newJob, "${workspaceRelativeFxRoot}/artifacts/bin/**/testResults.xml")
2189                                 Utilities.addXUnitDotNETResults(newJob, "${workspaceRelativeFxRoot}/artifacts/bin/**/testResults.xml")
2190
2191                                 //Archive additional build stuff to diagnose why my attempt at fault injection isn't causing CI to fail
2192                                 Utilities.addArchival(newJob, "SetStressModes.bat", "", true, false)
2193                                 Utilities.addArchival(newJob, "${workspaceRelativeFxRoot}/artifacts/bin/testhost/**", "", true, false)
2194                             }
2195                         }
2196                         else if (isGcReliabilityFramework(scenario)) {
2197                             buildCommands += "tests\\runtest.cmd ${runtestArguments} GenerateLayoutOnly"
2198                             buildCommands += "tests\\scripts\\run-gc-reliability-framework.cmd ${arch} ${configuration}"
2199                         }
2200                         else {
2201                             def buildCommandsStr = "call tests\\runtest.cmd ${runtestArguments}\r\n"
2202                             if (!isBuildOnly) {
2203                                 // If we ran the tests, collect the test logs collected by xunit. We want to do this even if the tests fail, so we
2204                                 // must do it in the same batch file as the test run.
2205
2206                                 buildCommandsStr += "echo on\r\n" // Show the following commands in the log. "echo" doesn't alter the errorlevel.
2207                                 buildCommandsStr += "set saved_errorlevel=%errorlevel%\r\n"
2208                                 buildCommandsStr += "powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::CreateFromDirectory('.\\bin\\tests\\${osGroup}.${arch}.${configuration}\\Reports', '.\\bin\\tests\\testReports.zip')\"\r\n";
2209                                 buildCommandsStr += "exit /b %saved_errorlevel%\r\n"
2210
2211                                 def doNotFailIfNothingArchived = true
2212                                 def archiveOnlyIfSuccessful = false
2213                                 Utilities.addArchival(newJob, "bin/tests/testReports.zip", "", doNotFailIfNothingArchived, archiveOnlyIfSuccessful)
2214                             }
2215                             buildCommands += buildCommandsStr
2216                         }
2217                     } // end if (!isBuildOnly)
2218
2219                     if (!doCoreFxTesting) {
2220                         // Run the rest of the build
2221                         // Build the mscorlib for the other OS's
2222                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} linuxmscorlib"
2223                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} osxmscorlib"
2224                        
2225                         if (arch == 'x64') {
2226                             buildCommands += "build.cmd ${lowerConfiguration} arm64 linuxmscorlib"
2227                         }
2228
2229                         if (!isJitStressScenario(scenario)) {
2230                             // Zip up the tests directory so that we don't use so much space/time copying
2231                             // 10s of thousands of files around.
2232                             buildCommands += "powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::CreateFromDirectory('.\\bin\\tests\\${osGroup}.${arch}.${configuration}', '.\\bin\\tests\\tests.zip')\"";
2233
2234                             // For Windows, pull full test results and test drops for x86/x64.
2235                             // No need to pull for stress mode scenarios (downstream builds use the default scenario)
2236                             Utilities.addArchival(newJob, "bin/Product/**,bin/tests/tests.zip", "bin/Product/**/.nuget/**")
2237                         }
2238
2239                         if (scenario == 'jitdiff') {
2240                             // retrieve jit-dasm output for base commit, and run jit-diff
2241                             if (!isBuildOnly) {
2242                                 // if this is a build only job, we want to keep the default (build) artifacts for the flow job
2243                                 Utilities.addArchival(newJob, "bin/tests/${osGroup}.${arch}.${configuration}/dasm/**")
2244                             }
2245                         }
2246
2247                         if (!isBuildOnly) {
2248                             Utilities.addXUnitDotNETResults(newJob, 'bin/**/TestRun*.xml', true)
2249                         }
2250                     }
2251
2252                     // Archive the logs, even if the build failed (which is when they are most interesting).
2253                     Utilities.addArchival(newJob, "bin/Logs/*.log,bin/Logs/*.wrn,bin/Logs/*.err,bin/Logs/MsbuildDebugLogs/*", "", /* doNotFailIfNothingArchived */ true, /* archiveOnlyIfSuccessful */ false)
2254                     break
2255                 case 'arm':
2256                 case 'arm64':
2257                     assert isArmWindowsScenario(scenario)
2258
2259                     def buildOpts = ''
2260
2261                     if (buildCoreclrTests) {
2262                         buildOpts += " -priority=${priority}"
2263                     } else {
2264                         buildOpts += ' skiptests'
2265                     }
2266
2267                     // This is now a build only job. Do not run tests. Use the flow job.
2268                     buildCommands += "set __TestIntermediateDir=int&&build.cmd ${lowerConfiguration} ${architecture} ${buildOpts}"
2269
2270                     if (doCoreFxTesting) {
2271                         assert isBuildOnly
2272
2273                         // Set the stress mode variables; this is incorporated into the generated CoreFx RunTests.cmd files.
2274                         def envScriptPath = ''
2275                         def buildCommandsStr = ''
2276                         envScriptPath = "%WORKSPACE%\\SetStressModes.bat"
2277                         buildCommandsStr += envScriptCreate(os, envScriptPath)
2278                         buildCommandsStr += envScriptSetStressModeVariables(os, Constants.jitStressModeScenarios[scenario], envScriptPath)
2279                         envScriptFinalize(os, envScriptPath)
2280                         buildCommands += buildCommandsStr
2281
2282                         def workspaceRelativeFxRootLinux = "_/fx"
2283                         def workspaceRelativeFxRootWin = "_\\fx"
2284                         def absoluteFxRoot = "%WORKSPACE%\\_\\fx"
2285                         def fxBranch = getFxBranch(branch)
2286
2287                         buildCommands += "python -u %WORKSPACE%\\tests\\scripts\\run-corefx-tests.py -arch ${architecture} -ci_arch ${architecture} -build_type ${configuration} -fx_root ${absoluteFxRoot} -fx_branch ${fxBranch} -env_script ${envScriptPath} -no_run_tests"
2288
2289                         // Zip up the CoreFx runtime and tests. We don't need the CoreCLR binaries; they have been copied to the CoreFX tree.
2290                         buildCommands += "powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::CreateFromDirectory('${workspaceRelativeFxRootWin}\\artifacts\\bin\\testhost\\netcoreapp-Windows_NT-Release-${architecture}', '${workspaceRelativeFxRootWin}\\fxruntime.zip')\"";
2291                         buildCommands += "powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::CreateFromDirectory('${workspaceRelativeFxRootWin}\\artifacts\\bin\\tests', '${workspaceRelativeFxRootWin}\\fxtests.zip')\"";
2292
2293                         Utilities.addArchival(newJob, "${workspaceRelativeFxRootLinux}/fxruntime.zip")
2294                         Utilities.addArchival(newJob, "${workspaceRelativeFxRootLinux}/fxtests.zip")
2295                     } else {
2296                         // Zip up the tests directory so that we don't use so much space/time copying
2297                         // 10s of thousands of files around.
2298                         buildCommands += "powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::CreateFromDirectory('.\\bin\\tests\\${osGroup}.${architecture}.${configuration}', '.\\bin\\tests\\tests.zip')\"";
2299
2300                         // Add archival.
2301                         Utilities.addArchival(newJob, "bin/Product/**,bin/tests/tests.zip", "bin/Product/**/.nuget/**")
2302                     }
2303
2304                     // Archive the logs, even if the build failed (which is when they are most interesting).
2305                     Utilities.addArchival(newJob, "bin/Logs/*.log,bin/Logs/*.wrn,bin/Logs/*.err,bin/Logs/MsbuildDebugLogs/*", "", /* doNotFailIfNothingArchived */ true, /* archiveOnlyIfSuccessful */ false)
2306                     break
2307                 default:
2308                     println("Unknown architecture: ${architecture}");
2309                     assert false
2310                     break
2311             }
2312             break
2313         // end case 'Windows_NT'; editor brace matching: }
2314         case 'Ubuntu':
2315         case 'Ubuntu16.04':
2316         case 'Ubuntu16.10':
2317         case 'Debian8.4':
2318         case 'OSX10.12':
2319         case 'CentOS7.1':
2320         case 'RHEL7.2':
2321         case 'Tizen':
2322         case 'Fedora24': // editor brace matching: {
2323             switch (architecture) {
2324                 case 'x86':
2325                     if (os == 'Ubuntu') {
2326                         // build and PAL test
2327                         def dockerImage = getDockerImageName(architecture, os, true)
2328                         buildCommands += "docker run -i --rm -v \${WORKSPACE}:/opt/code -w /opt/code -e ROOTFS_DIR=/crossrootfs/x86 ${dockerImage} ./build.sh ${architecture} cross ${lowerConfiguration}"
2329                         dockerImage = getDockerImageName(architecture, os, false)
2330                         buildCommands += "docker run -i --rm -v \${WORKSPACE}:/opt/code -w /opt/code ${dockerImage} ./src/pal/tests/palsuite/runpaltests.sh /opt/code/bin/obj/${osGroup}.${architecture}.${configuration} /opt/code/bin/paltestout"
2331                         Utilities.addArchival(newJob, "bin/Product/**,bin/obj/*/tests/**/*.so", "bin/Product/**/.nuget/**")
2332                         Utilities.addXUnitDotNETResults(newJob, '**/pal_tests.xml')
2333                     }
2334                     break
2335
2336                 case 'x64':
2337                     if (scenario == 'formatting') {
2338                         buildCommands += "python tests/scripts/format.py -c \${WORKSPACE} -o Linux -a ${architecture}"
2339                         Utilities.addArchival(newJob, "format.patch", "", true, false)
2340                         break
2341                     }
2342
2343                     if (scenario == 'pmi_asm_diffs') {
2344                         buildCommands += "./build.sh ${lowerConfiguration} ${architecture} skiptests skipbuildpackages"
2345                         buildCommands += "./build-test.sh ${lowerConfiguration} ${architecture} generatelayoutonly"
2346
2347                         // TODO: Add -target_branch and -commit_hash arguments based on GitHub variables.
2348                         buildCommands += "python -u \${WORKSPACE}/tests/scripts/run-pmi-diffs.py -arch ${architecture} -ci_arch ${architecture} -build_type ${configuration}"
2349
2350                         // Archive the asm
2351                         buildCommands += "tar -czf dasm.${os}.${architecture}.${configuration}.tgz ./_/pmi/asm"
2352                         Utilities.addArchival(newJob, "dasm.${os}.${architecture}.${configuration}.tgz")
2353                         break
2354                     }
2355
2356                     if (scenario == 'illink') {
2357                         assert(os == 'Ubuntu')
2358                         buildCommands += "./tests/scripts/build_illink.sh --clone --arch=${architecture}"
2359                     }
2360
2361                     if (!doCoreFxTesting) {
2362                         // We run pal tests on all OS but generate mscorlib (and thus, nuget packages)
2363                         // only on supported OS platforms.
2364                         def bootstrapRid = Utilities.getBoostrapPublishRid(os)
2365                         def bootstrapRidEnv = bootstrapRid != null ? "__PUBLISH_RID=${bootstrapRid} " : ''
2366
2367                         buildCommands += "${bootstrapRidEnv}./build.sh ${lowerConfiguration} ${architecture}"
2368
2369                         def testBuildOpts = ""
2370                         if (priority == '1') {
2371                             testBuildOpts = "priority1"
2372                         }
2373
2374                         buildCommands += "./build-test.sh ${lowerConfiguration} ${architecture} ${testBuildOpts}"
2375                         buildCommands += "src/pal/tests/palsuite/runpaltests.sh \${WORKSPACE}/bin/obj/${osGroup}.${architecture}.${configuration} \${WORKSPACE}/bin/paltestout"
2376
2377                         // Archive the bin/tests folder for *_tst jobs
2378                         def testArtifactsTgzFileName = getTestArtifactsTgzFileName(osGroup, architecture, configuration)
2379                         buildCommands += "tar -czf ${testArtifactsTgzFileName} bin/tests/${osGroup}.${architecture}.${configuration}"
2380                         Utilities.addArchival(newJob, "${testArtifactsTgzFileName}", "")
2381                         // And pal tests
2382                         Utilities.addXUnitDotNETResults(newJob, '**/pal_tests.xml')
2383                     }
2384                     else {
2385                         if (scenario == 'corefx_innerloop') {
2386                             assert os == 'Ubuntu' || 'OSX10.12'
2387                             assert architecture == 'x64'
2388
2389                             buildCommands += "./build.sh ${lowerConfiguration} ${architecture} skiptests"
2390                             buildCommands += "./build-test.sh ${lowerConfiguration} ${architecture} generatetesthostonly"
2391                             buildCommands += "./tests/runtest.sh ${lowerConfiguration} --corefxtestsall --testHostDir=\${WORKSPACE}/bin/tests/${osGroup}.${architecture}.${configuration}/testhost/ --coreclr-src=\${WORKSPACE}"
2392                             
2393                             break
2394                             // Archive and process (only) the test results
2395                             Utilities.addArchival(newJob, "bin/Logs/**/testResults.xml")
2396                             Utilities.addXUnitDotNETResults(newJob, "bin/Logs/**/testResults.xml")
2397                         }
2398                         else {
2399                             // Corefx stress testing
2400                             assert os == 'Ubuntu'
2401                             assert architecture == 'x64'
2402                             assert lowerConfiguration == 'checked'
2403                             assert isJitStressScenario(scenario)
2404
2405                             // Build coreclr
2406                             buildCommands += "./build.sh ${lowerConfiguration} ${architecture}"
2407
2408                             def scriptFileName = "\$WORKSPACE/set_stress_test_env.sh"
2409
2410                             def envScriptCmds = envScriptCreate(os, scriptFileName)
2411                             envScriptCmds += envScriptSetStressModeVariables(os, Constants.jitStressModeScenarios[scenario], scriptFileName)
2412                             envScriptCmds += envScriptFinalize(os, scriptFileName)
2413                             buildCommands += envScriptCmds
2414
2415                             // Build and text corefx
2416                             def workspaceRelativeFxRoot = "_/fx"
2417                             def absoluteFxRoot = "\$WORKSPACE/${workspaceRelativeFxRoot}"
2418                             def fxBranch = getFxBranch(branch)
2419
2420                             buildCommands += "python -u \$WORKSPACE/tests/scripts/run-corefx-tests.py -arch ${architecture} -ci_arch ${architecture} -build_type ${configuration} -fx_root ${absoluteFxRoot} -fx_branch ${fxBranch} -env_script ${scriptFileName}"
2421
2422                             // Archive and process (only) the test results
2423                             Utilities.addArchival(newJob, "${workspaceRelativeFxRoot}/artifacts/bin/**/testResults.xml")
2424                             Utilities.addXUnitDotNETResults(newJob, "${workspaceRelativeFxRoot}/artifacts/bin/**/testResults.xml")
2425                         }
2426                     }
2427
2428                     // Archive the logs, even if the build failed (which is when they are most interesting).
2429                     Utilities.addArchival(newJob, "bin/Logs/*.log,bin/Logs/*.wrn,bin/Logs/*.err,bin/Logs/MsbuildDebugLogs/*", "", /* doNotFailIfNothingArchived */ true, /* archiveOnlyIfSuccessful */ false)
2430                     break
2431                 case 'armem':
2432                     // Emulator cross builds for ARM runs on Tizen currently
2433                     assert os == 'Tizen'
2434
2435                     def arm_abi = "armel"
2436                     def linuxCodeName = "tizen"
2437
2438                     // Unzip the Windows test binaries first. Exit with 0
2439                     buildCommands += "unzip -q -o ./bin/tests/tests.zip -d ./bin/tests/Windows_NT.x64.${configuration} || exit 0"
2440
2441                     // Unpack the corefx binaries
2442                     buildCommands += "mkdir ./bin/CoreFxBinDir"
2443                     buildCommands += "tar -xf ./artifacts/bin/build.tar.gz -C ./bin/CoreFxBinDir"
2444
2445                     // Call the ARM CI script to cross build and test using docker
2446                     buildCommands += """./tests/scripts/arm32_ci_script.sh \\
2447                     --mode=docker \\
2448                     --${arm_abi} \\
2449                     --linuxCodeName=${linuxCodeName} \\
2450                     --buildConfig=${lowerConfiguration} \\
2451                     --testRootDir=./bin/tests/Windows_NT.x64.${configuration} \\
2452                     --coreFxBinDir=./bin/CoreFxBinDir \\
2453                     --testDirFile=./tests/testsRunningInsideARM.txt"""
2454
2455                     // Basic archiving of the build, no pal tests
2456                     Utilities.addArchival(newJob, "bin/Product/**,bin/obj/*/tests/**/*.dylib,bin/obj/*/tests/**/*.so", "bin/Product/**/.nuget/**")
2457                     break
2458                 case 'arm64':
2459                 case 'arm':
2460                     // Non-Windows ARM cross builds on hardware run on Ubuntu only
2461                     assert (os == 'Ubuntu') || (os == 'Ubuntu16.04')
2462
2463                     // Add some useful information to the log file. Ignore return codes.
2464                     buildCommands += "uname -a || true"
2465
2466                     // Cross build the Ubuntu/arm product using docker with a docker image that contains the correct
2467                     // Ubuntu cross-compilation toolset (running on a Ubuntu x64 host).
2468                     // For CoreFX testing, we only need the product build; we don't need to generate the layouts. The product
2469                     // build is then copied into the corefx layout by the run-corefx-test.py script. For CoreFX testing, we
2470                     // ZIP up the generated CoreFX runtime and tests.
2471
2472                     def dockerImage = getDockerImageName(architecture, os, true)
2473                     def dockerCmd = "docker run -i --rm -v \${WORKSPACE}:\${WORKSPACE} -w \${WORKSPACE} -e ROOTFS_DIR=/crossrootfs/${architecture} ${dockerImage} "
2474
2475                     buildCommands += "${dockerCmd}\${WORKSPACE}/build.sh ${lowerConfiguration} ${architecture} cross"
2476
2477                     if (doCoreFxTesting) {
2478                         def scriptFileName = "\$WORKSPACE/set_stress_test_env.sh"
2479
2480                         def envScriptCmds = envScriptCreate(os, scriptFileName)
2481                         envScriptCmds += envScriptSetStressModeVariables(os, Constants.jitStressModeScenarios[scenario], scriptFileName)
2482                         envScriptCmds += envScriptFinalize(os, scriptFileName)
2483                         buildCommands += envScriptCmds
2484
2485                         // Build and text corefx
2486                         def workspaceRelativeFxRootLinux = "_/fx"
2487                         def absoluteFxRoot = "\$WORKSPACE/${workspaceRelativeFxRootLinux}"
2488                         def fxBranch = getFxBranch(branch)
2489
2490                         buildCommands += "${dockerCmd}python -u \$WORKSPACE/tests/scripts/run-corefx-tests.py -arch ${architecture} -ci_arch ${architecture} -build_type ${configuration} -fx_root ${absoluteFxRoot} -fx_branch ${fxBranch} -env_script ${scriptFileName} -no_run_tests"
2491
2492                         // Docker creates files with root permission, so we need to zip in docker also, or else we'll get permission errors.
2493                         buildCommands += "${dockerCmd}zip -r ${workspaceRelativeFxRootLinux}/fxruntime.zip ${workspaceRelativeFxRootLinux}/artifacts/bin/testhost/netcoreapp-Linux-Release-${architecture}"
2494                         buildCommands += "${dockerCmd}zip -r ${workspaceRelativeFxRootLinux}/fxtests.zip ${workspaceRelativeFxRootLinux}/artifacts/bin/tests"
2495
2496                         Utilities.addArchival(newJob, "${workspaceRelativeFxRootLinux}/fxruntime.zip")
2497                         Utilities.addArchival(newJob, "${workspaceRelativeFxRootLinux}/fxtests.zip")
2498                     }
2499                     else if (isCrossGenComparisonScenario(scenario)) {
2500                         buildCommands += "${dockerCmd}\${WORKSPACE}/build-test.sh ${lowerConfiguration} ${architecture} cross generatelayoutonly"
2501
2502                         def workspaceRelativeProductBinDir = "bin/Product/${osGroup}.${architecture}.${configuration}"
2503                         def workspaceRelativeCoreLib = "${workspaceRelativeProductBinDir}/IL/System.Private.CoreLib.dll"
2504                         def workspaceRelativeCoreRootDir = "bin/tests/${osGroup}.${architecture}.${configuration}/Tests/Core_Root"
2505                         def workspaceRelativeCrossGenComparisonScript = "tests/scripts/crossgen_comparison.py"
2506                         def workspaceRelativeResultsDir = "_"
2507                         def workspaceRelativeArtifactsArchive = "${os}.${architecture}.${configuration}.${scenario}.zip"
2508                         def crossGenComparisonCmd = "python -u \${WORKSPACE}/${workspaceRelativeCrossGenComparisonScript} "
2509                         def crossArch = "x64"
2510                         def crossGenExecutable = "\${WORKSPACE}/${workspaceRelativeProductBinDir}/${crossArch}/crossgen"
2511                         def workspaceRelativeCrossArchResultDir = "${workspaceRelativeResultsDir}/${osGroup}.${crossArch}_${architecture}.${configuration}"
2512
2513                         buildCommands += "${dockerCmd}mkdir -p \${WORKSPACE}/${workspaceRelativeCrossArchResultDir}"
2514                         buildCommands += "${dockerCmd}${crossGenComparisonCmd}crossgen_corelib --crossgen ${crossGenExecutable} --il_corelib \${WORKSPACE}/${workspaceRelativeCoreLib} --result_dir \${WORKSPACE}/${workspaceRelativeCrossArchResultDir}"
2515                         buildCommands += "${dockerCmd}${crossGenComparisonCmd}crossgen_framework --crossgen ${crossGenExecutable} --core_root \${WORKSPACE}/${workspaceRelativeCoreRootDir} --result_dir \${WORKSPACE}/${workspaceRelativeCrossArchResultDir}"
2516
2517                         buildCommands += "${dockerCmd}zip -r ${workspaceRelativeArtifactsArchive} ${workspaceRelativeCoreLib} ${workspaceRelativeCoreRootDir} ${workspaceRelativeCrossGenComparisonScript} ${workspaceRelativeResultsDir}"
2518                         Utilities.addArchival(newJob, "${workspaceRelativeArtifactsArchive}")
2519                     }
2520                     else if (scenario == 'pmi_asm_diffs') {
2521                         buildCommands += "${dockerCmd}\${WORKSPACE}/build-test.sh ${lowerConfiguration} ${architecture} cross generatelayoutonly"
2522
2523                         // Pass `--skip_diffs` -- the actual diffs will be done on an arm machine in the test job. This is the build job.
2524                         // TODO: Add -target_branch and -commit_hash arguments based on GitHub variables.
2525                         buildCommands += "python -u \${WORKSPACE}/tests/scripts/run-pmi-diffs.py -arch ${architecture} -ci_arch ${architecture} -build_type ${configuration} --skip_diffs"
2526
2527                         // ZIP what we created.
2528                         buildCommands += "zip -r product.${os}.${architecture}.${lowerConfiguration}.zip ./bin/Product/Linux.${architecture}.${configuration}"
2529                         buildCommands += "zip -r product.baseline.${os}.${architecture}.${lowerConfiguration}.zip ./_/pmi/base/bin/Product/Linux.${architecture}.${configuration}"
2530                         buildCommands += "zip -r coreroot.${os}.${architecture}.${lowerConfiguration}.zip ./bin/tests/Linux.${architecture}.${configuration}/Tests/Core_Root"
2531                         buildCommands += "zip -r coreroot.baseline.${os}.${architecture}.${lowerConfiguration}.zip ./_/pmi/base/bin/tests/Linux.${architecture}.${configuration}/Tests/Core_Root"
2532
2533                         // Archive the built artifacts
2534                         Utilities.addArchival(newJob, "product.${os}.${architecture}.${lowerConfiguration}.zip,product.baseline.${os}.${architecture}.${lowerConfiguration}.zip,coreroot.${os}.${architecture}.${lowerConfiguration}.zip,coreroot.baseline.${os}.${architecture}.${lowerConfiguration}.zip")
2535                     }
2536                     else {
2537                         // Then, using the same docker image, build the tests and generate the CORE_ROOT layout.
2538
2539                         def testBuildOpts = ""
2540                         if (priority == '1') {
2541                             testBuildOpts = "priority1"
2542                         }
2543
2544                         buildCommands += "${dockerCmd}\${WORKSPACE}/build-test.sh ${lowerConfiguration} ${architecture} cross ${testBuildOpts}"
2545
2546                         // ZIP up the built tests (including CORE_ROOT and native test components copied to the CORE_ROOT) for the test job (created in the flow job code)
2547                         def testArtifactsTgzFileName = getTestArtifactsTgzFileName(osGroup, architecture, configuration)
2548                         buildCommands += "tar -czf ${testArtifactsTgzFileName} bin/tests/${osGroup}.${architecture}.${configuration}"
2549
2550                         Utilities.addArchival(newJob, "${testArtifactsTgzFileName}", "")
2551                     }
2552
2553                     // Archive the logs, even if the build failed (which is when they are most interesting).
2554                     Utilities.addArchival(newJob, "bin/Logs/*.log,bin/Logs/*.wrn,bin/Logs/*.err,bin/Logs/MsbuildDebugLogs/*", "", /* doNotFailIfNothingArchived */ true, /* archiveOnlyIfSuccessful */ false)
2555
2556                     // We need to clean up the build machines; the docker build leaves newly built files with root permission, which
2557                     // the cleanup task in Jenkins can't remove.
2558                     newJob.with {
2559                         publishers {
2560                             azureVMAgentPostBuildAction {
2561                                 agentPostBuildAction('Delete agent after build execution (when idle).')
2562                             }
2563                         }
2564                     }
2565                     break
2566                 default:
2567                     println("Unknown architecture: ${architecture}");
2568                     assert false
2569                     break
2570             }
2571             break
2572         // editor brace matching: }
2573         default:
2574             println("Unknown os: ${os}");
2575             assert false
2576             break
2577     } // os
2578
2579     return buildCommands
2580 }
2581
2582 // Determine if we should generate a job for the given parameters. This is for non-flow jobs: either build and test, or build only.
2583 // Returns true if the job should be generated.
2584 def static shouldGenerateJob(def scenario, def isPR, def architecture, def configuration, def os, def isBuildOnly)
2585 {
2586     // The various "innerloop" jobs are only available as PR triggered.
2587
2588     if (!isPR) {
2589         if (isInnerloopTestScenario(scenario)) {
2590             return false
2591         }
2592
2593         if (scenario == 'corefx_innerloop') {
2594             return false
2595         }
2596     }
2597
2598     // Tizen is only supported for armem architecture
2599     if (os == 'Tizen' && architecture != 'armem') {
2600         return false
2601     }
2602
2603     // Filter based on architecture.
2604
2605     switch (architecture) {
2606         case 'arm':
2607             if ((os != 'Windows_NT') && (os != 'Ubuntu')) {
2608                 return false
2609             }
2610             break
2611         case 'arm64':
2612             if ((os != 'Windows_NT') && (os != 'Ubuntu16.04')) {
2613                 return false
2614             }
2615             break
2616         case 'armem':
2617             if (os != 'Tizen') {
2618                 return false
2619             }
2620             break
2621         case 'x86':
2622             if ((os != 'Windows_NT') && (os != 'Ubuntu')) {
2623                 return false
2624             }
2625             break
2626         case 'x64':
2627             // Everything implemented
2628             break
2629         default:
2630             println("Unknown architecture: ${architecture}")
2631             assert false
2632             break
2633     }
2634
2635     // Which (Windows) build only jobs are required?
2636
2637     def isNormalOrInnerloop = (scenario == 'innerloop' || scenario == 'normal')
2638
2639     if (isBuildOnly) {
2640         switch (architecture) {
2641             case 'arm':
2642             case 'arm64':
2643                 // We use build only jobs for Windows arm/arm64 cross-compilation corefx testing, so we need to generate builds for that.
2644                 if (!isCoreFxScenario(scenario)) {
2645                     return false
2646                 }
2647                 break
2648             case 'x64':
2649             case 'x86':
2650                 if (!isNormalOrInnerloop) {
2651                     return false
2652                 }
2653                 break
2654             default:
2655                 return false
2656         }
2657     }
2658
2659     // Filter based on scenario.
2660
2661     if (isJitStressScenario(scenario)) {
2662         if (configuration != 'Checked') {
2663             return false
2664         }
2665
2666         def isEnabledOS = (os == 'Windows_NT') ||
2667                           (os == 'Ubuntu' && (architecture == 'x64') && isCoreFxScenario(scenario)) ||
2668                           (os == 'Ubuntu' && architecture == 'arm') ||
2669                           (os == 'Ubuntu16.04' && architecture == 'arm64')
2670         if (!isEnabledOS) {
2671             return false
2672         }
2673
2674         switch (architecture) {
2675             case 'x64':
2676                 break
2677
2678             case 'x86':
2679                 // x86 ubuntu: no stress modes
2680                 if (os == 'Ubuntu') {
2681                     return false
2682                 }
2683                 break
2684
2685             case 'arm':
2686             case 'arm64':
2687                 // We use build only jobs for Windows arm/arm64 cross-compilation corefx testing, so we need to generate builds for that.
2688                 // No "regular" Windows arm corefx jobs, e.g.
2689                 // For Ubuntu arm corefx testing, we use regular jobs (not "build only" since only Windows has "build only", and
2690                 // the Ubuntu arm "regular" jobs don't run tests anyway).
2691                 if (os == 'Windows_NT') {
2692                     if (! (isBuildOnly && isCoreFxScenario(scenario)) ) {
2693                         return false
2694                     }
2695                 }
2696                 else {
2697                     if (!isCoreFxScenario(scenario)) {
2698                         return false
2699                     }
2700                 }
2701                 break
2702
2703             default:
2704                 // armem: no stress jobs for ARM emulator.
2705                 return false
2706         }
2707     }
2708     else if (isR2RScenario(scenario)) {
2709         if (os != 'Windows_NT') {
2710             return false
2711         }
2712
2713         if (isR2RBaselineScenario(scenario)) {
2714             // no need for Debug scenario; Checked is sufficient
2715             if (configuration != 'Checked' && configuration != 'Release') {
2716                 return false
2717             }
2718         }
2719         else if (isR2RStressScenario(scenario)) {
2720             // Stress scenarios only run with Checked builds, not Release (they would work with Debug, but be slow).
2721             if (configuration != 'Checked') {
2722                 return false
2723             }
2724         }
2725
2726         switch (architecture) {
2727             case 'arm':
2728             case 'arm64':
2729                 // Windows arm/arm64 ready-to-run jobs use flow jobs and test jobs, but depend on "normal" (not R2R specific) build jobs.
2730                 return false
2731
2732             default:
2733                 break
2734         }
2735     }
2736     else if (isCrossGenComparisonScenario(scenario)) {
2737         return shouldGenerateCrossGenComparisonJob(os, architecture, configuration, scenario)
2738     }
2739     else {
2740         // Skip scenarios
2741         switch (scenario) {
2742             case 'ilrt':
2743                 // The ilrt build isn't necessary except for Windows_NT2003.  Non-Windows NT uses
2744                 // the default scenario build
2745                 if (os != 'Windows_NT') {
2746                     return false
2747                 }
2748                 // Only x64 for now
2749                 if (architecture != 'x64') {
2750                     return false
2751                 }
2752                 // Release only
2753                 if (configuration != 'Release') {
2754                     return false
2755                 }
2756                 break
2757             case 'jitdiff':
2758                 if (os != 'Windows_NT' && os != 'Ubuntu' && os != 'OSX10.12') {
2759                     return false
2760                 }
2761                 if (architecture != 'x64') {
2762                     return false
2763                 }
2764                 if (configuration != 'Checked') {
2765                     return false
2766                 }
2767                 break
2768             case 'longgc':
2769             case 'gcsimulator':
2770                 if (os != 'Windows_NT' && os != 'Ubuntu' && os != 'OSX10.12') {
2771                     return false
2772                 }
2773                 if (architecture != 'x64') {
2774                     return false
2775                 }
2776                 if (configuration != 'Release') {
2777                     return false
2778                 }
2779                 break
2780             case 'gc_reliability_framework':
2781             case 'standalone_gc':
2782                 if (os != 'Windows_NT' && os != 'Ubuntu' && os != 'OSX10.12') {
2783                     return false
2784                 }
2785
2786                 if (architecture != 'x64') {
2787                     return false
2788                 }
2789
2790                 if (configuration != 'Release' && configuration != 'Checked') {
2791                     return false
2792                 }
2793                 break
2794             // We only run Windows and Ubuntu x64 Checked for formatting right now
2795             case 'formatting':
2796                 if (os != 'Windows_NT' && os != 'Ubuntu') {
2797                     return false
2798                 }
2799                 if (architecture != 'x64') {
2800                     return false
2801                 }
2802                 if (configuration != 'Checked') {
2803                     return false
2804                 }
2805                 break
2806             case 'illink':
2807                 if (os != 'Windows_NT' && (os != 'Ubuntu' || architecture != 'x64')) {
2808                     return false
2809                 }
2810                 if (architecture != 'x64' && architecture != 'x86') {
2811                     return false
2812                 }
2813                 break
2814             case 'normal':
2815                 // Nothing skipped
2816                 break
2817             case 'innerloop':
2818                 if (!isValidPrTriggeredInnerLoopJob(os, architecture, configuration, isBuildOnly)) {
2819                     return false
2820                 }
2821                 break
2822             case 'corefx_innerloop':
2823                 if (os != 'Windows_NT' && os != 'Ubuntu' &&  os != 'OSX10.12') {
2824                     return false
2825                 }
2826                 if (architecture != 'x64') {
2827                     return false
2828                 }
2829                 break
2830             case 'pmi_asm_diffs':
2831                 if (configuration != 'Checked') {
2832                     return false
2833                 }
2834                 if (architecture == 'armem') {
2835                     return false
2836                 }
2837                 // Currently, we don't support pmi_asm_diffs for Windows arm/arm64. We don't have a dotnet CLI available to
2838                 // build jitutils. The jobs are not in validArmWindowsScenarios.
2839                 if ((os == 'Windows_NT') && (architecture == 'arm' || architecture == 'arm64')) {
2840                     return false
2841                 }
2842                 // Currently, no support for Linux x86.
2843                 if ((os != 'Windows_NT') && (architecture == 'x86')) {
2844                     return false
2845                 }
2846                 break
2847             default:
2848                 println("Unknown scenario: ${scenario}")
2849                 assert false
2850                 break
2851         }
2852     }
2853
2854     // The job was not filtered out, so we should generate it!
2855     return true
2856 }
2857
2858 Constants.allScenarios.each { scenario ->
2859     [true, false].each { isPR ->
2860         Constants.architectureList.each { architecture ->
2861             Constants.configurationList.each { configuration ->
2862                 Constants.osList.each { os ->
2863                     // If the OS is Windows_NT_BuildOnly, set the isBuildOnly flag to true
2864                     // and reset the os to Windows_NT
2865                     def isBuildOnly = false
2866                     if (os == 'Windows_NT_BuildOnly') {
2867                         isBuildOnly = true
2868                         os = 'Windows_NT'
2869                     }
2870
2871                     if (!shouldGenerateJob(scenario, isPR, architecture, configuration, os, isBuildOnly)) {
2872                         return
2873                     }
2874
2875                     // Calculate names
2876                     def jobName = getJobName(configuration, architecture, os, scenario, isBuildOnly)
2877                     def folderName = getJobFolder(scenario)
2878
2879                     // Create the new job
2880                     def newJob = job(Utilities.getFullJobName(project, jobName, isPR, folderName)) {}
2881
2882                     addToViews(newJob, false, isPR, architecture, os, configuration, scenario) // isFlowJob == false
2883
2884                     setJobMachineAffinity(architecture, os, true, false, false, newJob) // isBuildJob = true, isTestJob = false, isFlowJob = false
2885
2886                     Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
2887                     addTriggers(newJob, branch, isPR, architecture, os, configuration, scenario, false, isBuildOnly) // isFlowJob==false
2888                     setJobTimeout(newJob, isPR, architecture, configuration, scenario, isBuildOnly)
2889
2890                     // Copy Windows build test binaries and corefx build artifacts for Linux cross build for armem.
2891                     // We don't use a flow job for this, but we do depend on there being existing builds with these
2892                     // artifacts produced.
2893                     if ((architecture == 'armem') && (os == 'Tizen')) {
2894                         // Define the Windows Tests and Corefx build job names
2895                         def lowerConfiguration = configuration.toLowerCase()
2896                         def WindowsTestsName = projectFolder + '/' +
2897                                                Utilities.getFullJobName(project,
2898                                                                         getJobName(lowerConfiguration, 'x64' , 'windows_nt', 'normal', true),
2899                                                                         false)
2900                         def fxBranch = getFxBranch(branch)
2901                         def corefxFolder = Utilities.getFolderName('dotnet/corefx') + '/' +
2902                                            Utilities.getFolderName(fxBranch)
2903
2904                         def arm_abi = 'armel'
2905                         def corefx_os = 'tizen'
2906
2907                         // Let's use release CoreFX to test checked CoreCLR,
2908                         // because we do not generate checked CoreFX in CoreFX CI yet.
2909                         def corefx_lowerConfiguration = lowerConfiguration
2910                         if (lowerConfiguration == 'checked') {
2911                             corefx_lowerConfiguration = 'release'
2912                         }
2913
2914                         // Copy the Windows test binaries and the Corefx build binaries
2915                         newJob.with {
2916                             steps {
2917                                 copyArtifacts(WindowsTestsName) {
2918                                     includePatterns('bin/tests/tests.zip')
2919                                     buildSelector {
2920                                         latestSuccessful(true)
2921                                     }
2922                                 }
2923                                 copyArtifacts("${corefxFolder}/${corefx_os}_${arm_abi}_cross_${corefx_lowerConfiguration}") {
2924                                     includePatterns('artifacts/bin/build.tar.gz')
2925                                     buildSelector {
2926                                         latestSuccessful(true)
2927                                     }
2928                                 }
2929                             } // steps
2930                         } // newJob.with
2931                     }
2932
2933                     def buildCommands = calculateBuildCommands(newJob, scenario, branch, isPR, architecture, configuration, os, isBuildOnly)
2934
2935                     newJob.with {
2936                         steps {
2937                             if (os == 'Windows_NT') {
2938                                 buildCommands.each { buildCommand ->
2939                                     batchFile(buildCommand)
2940                                 }
2941                             }
2942                             else {
2943                                 buildCommands.each { buildCommand ->
2944                                     shell(buildCommand)
2945                                 }
2946                             }
2947                         } // steps
2948                     } // newJob.with
2949
2950                 } // os
2951             } // configuration
2952         } // architecture
2953     } // isPR
2954 } // scenario
2955
2956 // Create a Windows ARM/ARM64 test job that will be used by a flow job.
2957 // Returns the newly created job.
2958 def static CreateWindowsArmTestJob(def dslFactory, def project, def architecture, def os, def configuration, def scenario, def isPR, def inputCoreCLRBuildName)
2959 {
2960     def osGroup = getOSGroup(os)
2961     def jobName = getJobName(configuration, architecture, os, scenario, false) + "_tst"
2962
2963     def jobFolder = getJobFolder(scenario)
2964     def newJob = dslFactory.job(Utilities.getFullJobName(project, jobName, isPR, jobFolder)) {
2965         parameters {
2966             stringParam('CORECLR_BUILD', '', "Build number to copy CoreCLR ${osGroup} binaries from")
2967         }
2968
2969         steps {
2970             // Set up the copies
2971
2972             // Coreclr build we are trying to test
2973             //
2974             //  ** NOTE ** This will, correctly, overwrite the CORE_ROOT from the Windows test archive
2975
2976             copyArtifacts(inputCoreCLRBuildName) {
2977                 excludePatterns('**/testResults.xml', '**/*.ni.dll')
2978                 buildSelector {
2979                     buildNumber('${CORECLR_BUILD}')
2980                 }
2981             }
2982
2983             if (isCoreFxScenario(scenario)) {
2984
2985                 // Only arm/arm64 supported for corefx testing now.
2986                 assert architecture == 'arm' || architecture == 'arm64'
2987
2988                 // Unzip CoreFx runtime
2989                 batchFile("powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::ExtractToDirectory('_\\fx\\fxruntime.zip', '_\\fx\\artifacts\\bin\\testhost\\netcoreapp-Windows_NT-Release-${architecture}')\"")
2990
2991                 // Unzip CoreFx tests.
2992                 batchFile("powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::ExtractToDirectory('_\\fx\\fxtests.zip', '_\\fx\\artifacts\\bin\\tests')\"")
2993
2994                 // Add the script to run the corefx tests
2995                 def corefx_runtime_path   = "%WORKSPACE%\\_\\fx\\artifacts\\bin\\testhost\\netcoreapp-Windows_NT-Release-${architecture}"
2996                 def corefx_tests_dir      = "%WORKSPACE%\\_\\fx\\artifacts\\bin\\tests"
2997                 def corefx_exclusion_file = "%WORKSPACE%\\tests\\${architecture}\\corefx_test_exclusions.txt"
2998                 batchFile("call %WORKSPACE%\\tests\\scripts\\run-corefx-tests.bat ${corefx_runtime_path} ${corefx_tests_dir} ${corefx_exclusion_file} ${architecture}")
2999
3000             } else { // !isCoreFxScenario(scenario)
3001
3002                 // Unzip tests.
3003                 batchFile("powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::ExtractToDirectory('bin\\tests\\tests.zip', 'bin\\tests\\${osGroup}.${architecture}.${configuration}')\"")
3004
3005                 def buildCommands = ""
3006
3007                 def coreRootLocation = "%WORKSPACE%\\bin\\tests\\Windows_NT.${architecture}.${configuration}\\Tests\\Core_Root"
3008                 def addEnvVariable =  { variable, value -> buildCommands += "set ${variable}=${value}\r\n"}
3009                 def addCommand = { cmd -> buildCommands += "${cmd}\r\n"}
3010
3011                 // Make sure Command Extensions are enabled. Used so %ERRORLEVEL% is available.
3012                 addCommand("SETLOCAL ENABLEEXTENSIONS")
3013
3014                 // For all jobs 
3015                 addEnvVariable("CORE_ROOT", coreRootLocation)
3016                 addEnvVariable("COMPlus_NoGuiOnAssert", "1")
3017                 addEnvVariable("COMPlus_ContinueOnAssert", "0")
3018
3019                 // If we are running a stress mode, we'll set those variables as well
3020                 if (isJitStressScenario(scenario) || isR2RStressScenario(scenario)) {
3021                     def stressValues = null
3022                     if (isJitStressScenario(scenario)) {
3023                         stressValues = Constants.jitStressModeScenarios[scenario]
3024                     }
3025                     else {
3026                         stressValues = Constants.r2rStressScenarios[scenario]
3027                     }
3028
3029                     stressValues.each { key, value -> 
3030                         addEnvVariable(key, value)
3031                     }
3032                 }
3033
3034                 if (isR2RScenario(scenario)) {
3035                     // Crossgen the framework assemblies.
3036                     buildCommands += """
3037 @for %%F in (%CORE_ROOT%\\*.dll) do @call :PrecompileAssembly "%CORE_ROOT%" "%%F" %%~nxF
3038 @goto skip_PrecompileAssembly
3039
3040 :PrecompileAssembly
3041 @REM Skip mscorlib since it is already precompiled.
3042 @if /I "%3" == "mscorlib.dll" exit /b 0
3043 @if /I "%3" == "mscorlib.ni.dll" exit /b 0
3044
3045 "%CORE_ROOT%\\crossgen.exe" /Platform_Assemblies_Paths "%CORE_ROOT%" %2 >nul 2>nul
3046 @if "%errorlevel%" == "-2146230517" (
3047     echo %2 is not a managed assembly.
3048 ) else if "%errorlevel%" == "-2146234344" (
3049     echo %2 is not a managed assembly.
3050 ) else if %errorlevel% neq 0 (
3051     echo Unable to precompile %2
3052 ) else (
3053     echo Precompiled %2
3054 )
3055 @exit /b 0
3056
3057 :skip_PrecompileAssembly
3058 """
3059
3060                     // Set RunCrossGen variable to cause test wrappers to invoke their logic to run
3061                     // crossgen on tests before running them.
3062                     addEnvVariable("RunCrossGen", "true")
3063                 } // isR2RScenario(scenario)
3064
3065                 // Run runtest.cmd
3066                 // Do not run generate layout. It will delete the correct CORE_ROOT, and we do not have a correct product
3067                 // dir to copy from.
3068                 def runtestCommand = "call %WORKSPACE%\\tests\\runtest.cmd ${architecture} ${configuration} skipgeneratelayout"
3069
3070                 addCommand("${runtestCommand}")
3071                 addCommand("echo on") // Show the following commands in the log. "echo" doesn't alter the errorlevel.
3072                 addCommand("set saved_errorlevel=%errorlevel%")
3073
3074                 // Collect the test logs collected by xunit. Ignore errors here. We want to collect these even if the run
3075                 // failed for some reason, so it needs to be in this batch file.
3076
3077                 addCommand("powershell -NoProfile -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::CreateFromDirectory('.\\bin\\tests\\${osGroup}.${architecture}.${configuration}\\Reports', '.\\bin\\tests\\testReports.zip')\"");
3078
3079                 // Use the runtest.cmd errorlevel as the script errorlevel.
3080                 addCommand("exit /b %saved_errorlevel%")
3081
3082                 batchFile(buildCommands)
3083             } // non-corefx testing
3084         } // steps
3085     } // job
3086
3087     if (!isCoreFxScenario(scenario)) {
3088         def doNotFailIfNothingArchived = true
3089         def archiveOnlyIfSuccessful = false
3090         Utilities.addArchival(newJob, "bin/tests/testReports.zip", "", doNotFailIfNothingArchived, archiveOnlyIfSuccessful)
3091
3092         Utilities.addXUnitDotNETResults(newJob, 'bin/**/TestRun*.xml', true)
3093     }
3094
3095     return newJob
3096 }
3097
3098 // Create a test job not covered by the "Windows ARM" case that will be used by a flow job.
3099 // E.g., non-Windows tests.
3100 // Returns the newly created job.
3101 def static CreateOtherTestJob(def dslFactory, def project, def branch, def architecture, def os, def configuration, def scenario, def isPR, def inputCoreCLRBuildName)
3102 {
3103     def lowerConfiguration = configuration.toLowerCase()
3104
3105     def isUbuntuArm64Job = ((os == "Ubuntu16.04") && (architecture == 'arm64'))
3106     def isUbuntuArm32Job = ((os == "Ubuntu") && (architecture == 'arm'))
3107     def isUbuntuArmJob = isUbuntuArm32Job || isUbuntuArm64Job
3108
3109     def doCoreFxTesting = isCoreFxScenario(scenario)
3110     def isPmiAsmDiffsScenario = (scenario == 'pmi_asm_diffs')
3111
3112     def workspaceRelativeFxRootLinux = "_/fx" // only used for CoreFX testing
3113
3114     def osGroup = getOSGroup(os)
3115     def jobName = getJobName(configuration, architecture, os, scenario, false) + "_tst"
3116
3117     def testOpts = ''
3118     def useServerGC = false
3119
3120     // Enable Server GC for Ubuntu PR builds
3121     // REVIEW: why? Does this apply to all architectures? Why only PR?
3122     if (os == 'Ubuntu' && isPR) {
3123         testOpts += ' --useServerGC'
3124         useServerGC = true
3125     }
3126
3127     if (isR2RScenario(scenario)) {
3128
3129         testOpts += ' --crossgen --runcrossgentests'
3130
3131         if (scenario == 'r2r_jitstress1') {
3132             testOpts += ' --jitstress=1'
3133         }
3134         else if (scenario == 'r2r_jitstress2') {
3135             testOpts += ' --jitstress=2'
3136         }
3137         else if (scenario == 'r2r_jitstress1_tiered') {
3138             testOpts += ' --jitstress=1'
3139         }
3140         else if (scenario == 'r2r_jitstress2_tiered') {
3141             testOpts += ' --jitstress=2'
3142         }
3143         else if (scenario == 'r2r_jitstressregs1') {
3144             testOpts += ' --jitstressregs=1'
3145         }
3146         else if (scenario == 'r2r_jitstressregs2') {
3147             testOpts += ' --jitstressregs=2'
3148         }
3149         else if (scenario == 'r2r_jitstressregs3') {
3150             testOpts += ' --jitstressregs=3'
3151         }
3152         else if (scenario == 'r2r_jitstressregs4') {
3153             testOpts += ' --jitstressregs=4'
3154         }
3155         else if (scenario == 'r2r_jitstressregs8') {
3156             testOpts += ' --jitstressregs=8'
3157         }
3158         else if (scenario == 'r2r_jitstressregs0x10') {
3159             testOpts += ' --jitstressregs=0x10'
3160         }
3161         else if (scenario == 'r2r_jitstressregs0x80') {
3162             testOpts += ' --jitstressregs=0x80'
3163         }
3164         else if (scenario == 'r2r_jitstressregs0x1000') {
3165             testOpts += ' --jitstressregs=0x1000'
3166         }
3167         else if (scenario == 'r2r_jitminopts') {
3168             testOpts += ' --jitminopts'
3169         }
3170         else if (scenario == 'r2r_jitforcerelocs') {
3171             testOpts += ' --jitforcerelocs'
3172         }
3173         else if (scenario == 'r2r_gcstress15') {
3174             testOpts += ' --gcstresslevel=0xF'
3175         }
3176     }
3177     else if (scenario == 'jitdiff') {
3178         testOpts += ' --jitdisasm --crossgen'
3179     }
3180     else if (scenario == 'illink') {
3181         testOpts += ' --link=\$WORKSPACE/linker/linker/bin/netcore_Release/netcoreapp2.0/ubuntu-x64/publish/illink'
3182     }
3183     else if (isLongGc(scenario)) {
3184         // Long GC tests behave very poorly when they are not
3185         // the only test running (many of them allocate until OOM).
3186         testOpts += ' --sequential'
3187
3188         // A note - runtest.sh does have "--long-gc" and "--gcsimulator" options
3189         // for running long GC and GCSimulator tests, respectively. We don't use them
3190         // here because using a playlist file produces much more readable output on the CI machines
3191         // and reduces running time.
3192         //
3193         // The Long GC playlist contains all of the tests that are
3194         // going to be run. The GCSimulator playlist contains all of
3195         // the GC simulator tests.
3196         if (scenario == 'longgc') {
3197             testOpts += ' --long-gc --playlist=./tests/longRunningGcTests.txt'
3198         }
3199         else if (scenario == 'gcsimulator') {
3200             testOpts += ' --gcsimulator --playlist=./tests/gcSimulatorTests.txt'
3201         }
3202     }
3203     else if (isGcReliabilityFramework(scenario)) {
3204         testOpts += ' --build-overlay-only'
3205     }
3206     else if (scenario == 'standalone_gc') {
3207         if (osGroup == 'OSX') {
3208             testOpts += ' --gcname=libclrgc.dylib'
3209         }
3210         else if (osGroup == 'Linux') {
3211             testOpts += ' --gcname=libclrgc.so'
3212         }
3213         else {
3214             println("Unexpected OS group: ${osGroup} for os ${os}")
3215             assert false
3216         }
3217     }
3218
3219     def jobFolder = getJobFolder(scenario)
3220     def newJob = dslFactory.job(Utilities.getFullJobName(project, jobName, isPR, jobFolder)) {
3221         parameters {
3222             stringParam('CORECLR_BUILD', '', "Build number to copy CoreCLR ${osGroup} binaries from")
3223         }
3224
3225         steps {
3226             // Set up the copies
3227
3228             // Coreclr build we are trying to test
3229             //
3230             // HACK: the Ubuntu arm64 copyArtifacts Jenkins plug-in is ridiculously slow (45 minutes to
3231             // 1.5 hours for this step). Instead, directly use wget, which is fast (1 minute).
3232
3233             if (!isUbuntuArm64Job) {
3234                 copyArtifacts(inputCoreCLRBuildName) {
3235                     excludePatterns('**/testResults.xml', '**/*.ni.dll')
3236                     buildSelector {
3237                         buildNumber('${CORECLR_BUILD}')
3238                     }
3239                 }
3240             }
3241
3242             if (isUbuntuArmJob) {
3243                 // Add some useful information to the log file. Ignore return codes.
3244                 shell("uname -a || true")
3245             }
3246
3247             if (isUbuntuArm64Job) {
3248                 // Copy the required artifacts directly, using wget, e.g.:
3249                 // 
3250                 //  https://ci.dot.net/job/dotnet_coreclr/job/master/job/arm64_cross_checked_ubuntu16.04_innerloop_prtest/16/artifact/testnativebin.checked.zip
3251                 //  https://ci.dot.net/job/dotnet_coreclr/job/master/job/arm64_cross_checked_ubuntu16.04_innerloop_prtest/16/artifact/tests.checked.zip
3252                 // 
3253                 // parameterized as:
3254                 //
3255                 //  https://ci.dot.net/job/${mungedProjectName}/job/${mungedBranchName}/job/${inputJobName}/${CORECLR_BUILD}/artifact/testnativebin.checked.zip
3256                 //  https://ci.dot.net/job/${mungedProjectName}/job/${mungedBranchName}/job/${inputJobName}/${CORECLR_BUILD}/artifact/tests.checked.zip
3257                 //
3258                 // CoreFX example artifact URLs:
3259                 //
3260                 //  https://ci.dot.net/job/dotnet_coreclr/job/dev_unix_test_workflow/job/jitstress/job/arm64_cross_checked_ubuntu16.04_corefx_baseline_prtest/1/artifact/_/fx/fxruntime.zip
3261                 //  https://ci.dot.net/job/dotnet_coreclr/job/dev_unix_test_workflow/job/jitstress/job/arm64_cross_checked_ubuntu16.04_corefx_baseline_prtest/1/artifact/_/fx/fxtests.zip
3262                 //
3263                 // Note that the source might be in a "jitstress" folder.
3264                 //
3265                 // Use `--progress=dot:giga` to display some progress output, but limit it in the log file.
3266                 //
3267                 // Use `--directory-prefix=_/fx` to specify where to put the corefx files (to match what other platforms do). Use this instead of `-O`.
3268
3269                 shell("echo \"Using wget instead of the Jenkins copy artifacts plug-in to copy artifacts from ${inputCoreCLRBuildName}\"")
3270
3271                 def mungedProjectName = Utilities.getFolderName(project)
3272                 def mungedBranchName = Utilities.getFolderName(branch)
3273
3274                 def doCrossGenComparison = isCrossGenComparisonScenario(scenario)
3275                 def inputCoreCLRBuildScenario = isInnerloopTestScenario(scenario) ? 'innerloop' : 'normal'
3276                 if (isPmiAsmDiffsScenario || doCoreFxTesting || doCrossGenComparison) {
3277                     // These depend on unique builds for each scenario
3278                     inputCoreCLRBuildScenario = scenario
3279                 }
3280                 def sourceJobName = getJobName(configuration, architecture, os, inputCoreCLRBuildScenario, false)
3281                 def inputJobName = Utilities.getFullJobName(sourceJobName, isPR)
3282
3283                 // Need to add the sub-folder if necessary.
3284                 def inputJobPath = "job/${inputJobName}"
3285                 def folderName = getJobFolder(inputCoreCLRBuildScenario)
3286                 if (folderName != '') {
3287                     inputJobPath = "job/${folderName}/job/${inputJobName}"
3288                 }
3289
3290                 def inputUrlRoot = "https://ci.dot.net/job/${mungedProjectName}/job/${mungedBranchName}/${inputJobPath}/\${CORECLR_BUILD}/artifact"
3291
3292                 if (isPmiAsmDiffsScenario) {
3293                     def workspaceRelativeRootLinux = "_/pmi"
3294                     shell("mkdir -p ${workspaceRelativeRootLinux}")
3295                     shell("wget --progress=dot:giga ${inputUrlRoot}/product.${os}.${architecture}.${lowerConfiguration}.zip")
3296                     shell("wget --progress=dot:giga ${inputUrlRoot}/product.baseline.${os}.${architecture}.${lowerConfiguration}.zip")
3297                     shell("wget --progress=dot:giga ${inputUrlRoot}/coreroot.${os}.${architecture}.${lowerConfiguration}.zip")
3298                     shell("wget --progress=dot:giga ${inputUrlRoot}/coreroot.baseline.${os}.${architecture}.${lowerConfiguration}.zip")
3299                 }
3300                 else if (doCoreFxTesting) {
3301                     shell("mkdir -p ${workspaceRelativeFxRootLinux}")
3302                     shell("wget --progress=dot:giga --directory-prefix=${workspaceRelativeFxRootLinux} ${inputUrlRoot}/${workspaceRelativeFxRootLinux}/fxtests.zip")
3303                     shell("wget --progress=dot:giga --directory-prefix=${workspaceRelativeFxRootLinux} ${inputUrlRoot}/${workspaceRelativeFxRootLinux}/fxruntime.zip")
3304                 }
3305                 else {
3306                     def testArtifactsTgzFileName = getTestArtifactsTgzFileName(osGroup, architecture, configuration)
3307                     shell("wget --progress=dot:giga ${inputUrlRoot}/${testArtifactsTgzFileName}")
3308                 }
3309             }
3310
3311             if (architecture == 'x86') {
3312                 shell("mkdir ./bin/CoreFxNative")
3313
3314                 def fxBranch = getFxBranch(branch)
3315                 def corefxFolder = Utilities.getFolderName('dotnet/corefx') + '/' + Utilities.getFolderName(fxBranch)
3316
3317                 copyArtifacts("${corefxFolder}/ubuntu16.04_x86_release") {
3318                     includePatterns('artifacts/bin/build.tar.gz')
3319                     targetDirectory('bin/CoreFxNative')
3320                     buildSelector {
3321                         latestSuccessful(true)
3322                     }
3323                 }
3324
3325                 shell("mkdir ./bin/CoreFxBinDir")
3326                 shell("tar -xf ./bin/CoreFxNative/artifacts/bin/build.tar.gz -C ./bin/CoreFxBinDir")
3327             }
3328
3329             if (isPmiAsmDiffsScenario) {
3330                 // TODO: add back "-q" when we know it works
3331                 shell("unzip -o ./product.${os}.${architecture}.${lowerConfiguration}.zip || exit 0")
3332                 shell("unzip -o ./product.baseline.${os}.${architecture}.${lowerConfiguration}.zip || exit 0")
3333                 shell("unzip -o ./coreroot.${os}.${architecture}.${lowerConfiguration}.zip || exit 0")
3334                 shell("unzip -o ./coreroot.baseline.${os}.${architecture}.${lowerConfiguration}.zip || exit 0")
3335             }
3336             // CoreFX testing downloads the CoreFX tests, not the coreclr tests. Also, unzip the built CoreFX layout/runtime directories.
3337             else if (doCoreFxTesting) {
3338                 shell("unzip -q -o ${workspaceRelativeFxRootLinux}/fxtests.zip || exit 0")
3339                 shell("unzip -q -o ${workspaceRelativeFxRootLinux}/fxruntime.zip || exit 0")
3340             }
3341             else {
3342                 def testArtifactsTgzFileName = getTestArtifactsTgzFileName(osGroup, architecture, configuration)
3343                 shell("tar -xzf ./${testArtifactsTgzFileName} || exit 0") // extracts to ./bin/tests/${osGroup}.${architecture}.${configuration}
3344             }
3345
3346             // Execute the tests
3347             def runDocker = isNeedDocker(architecture, os, false)
3348             def dockerPrefix = ""
3349             def dockerCmd = ""
3350             if (runDocker) {
3351                 def dockerImage = getDockerImageName(architecture, os, false)
3352                 dockerPrefix = "docker run -i --rm -v \${WORKSPACE}:\${WORKSPACE} -w \${WORKSPACE} "
3353                 dockerCmd = dockerPrefix + "${dockerImage} "
3354             }
3355
3356             // If we are running a stress mode, we'll set those variables first.
3357             // For CoreFX, the stress variables are already built into the CoreFX test build per-test wrappers.
3358             if (!doCoreFxTesting && isJitStressScenario(scenario)) {
3359                 def scriptFileName = "\${WORKSPACE}/set_stress_test_env.sh"
3360                 def envScriptCmds = envScriptCreate(os, scriptFileName)
3361                 envScriptCmds += envScriptSetStressModeVariables(os, Constants.jitStressModeScenarios[scenario], scriptFileName)
3362                 envScriptCmds += envScriptFinalize(os, scriptFileName)
3363                 shell("${envScriptCmds}")
3364                 testOpts += " --test-env=${scriptFileName}"
3365             }
3366
3367             // setup-stress-dependencies.sh, invoked by runtest.sh to download the coredistools package, depends on the "dotnet"
3368             // tool downloaded by the "init-tools.sh" script. However, it only invokes setup-stress-dependencies.sh for x64. The
3369             // coredistools package is used by GCStress on x86 and x64 to disassemble code to determine instruction boundaries.
3370             // On arm/arm64, it is not required as determining instruction boundaries is trivial.
3371             if (isGCStressRelatedTesting(scenario)) {
3372                 if (architecture == 'x64') {
3373                     shell('./init-tools.sh')
3374                 }
3375             }
3376
3377             if (isPmiAsmDiffsScenario) {
3378                 shell("""\
3379 python -u \${WORKSPACE}/tests/scripts/run-pmi-diffs.py -arch ${architecture} -ci_arch ${architecture} -build_type ${configuration} --skip_baseline_build""")
3380
3381                 shell("zip -r dasm.${os}.${architecture}.${configuration}.zip ./_/pmi/asm")
3382             }
3383             else if (doCoreFxTesting) {
3384                 shell("""\
3385 \${WORKSPACE}/tests/scripts/run-corefx-tests.sh --test-exclude-file \${WORKSPACE}/tests/${architecture}/corefx_linux_test_exclusions.txt --runtime \${WORKSPACE}/${workspaceRelativeFxRootLinux}/artifacts/bin/testhost/netcoreapp-Linux-Release-${architecture} --arch ${architecture} --corefx-tests \${WORKSPACE}/${workspaceRelativeFxRootLinux}/artifacts/bin --configurationGroup Release""")
3386             }
3387             else {
3388                 def runScript = "${dockerCmd}./tests/runtest.sh"
3389
3390                 shell("""\
3391 ${runScript} \\
3392     ${lowerConfiguration} \\
3393     --testRootDir=\"\${WORKSPACE}/bin/tests/${osGroup}.${architecture}.${configuration}\" \\
3394     --coreOverlayDir=\"\${WORKSPACE}/bin/tests/${osGroup}.${architecture}.${configuration}/Tests/Core_Root\" \\
3395     --limitedDumpGeneration ${testOpts}""")
3396             }
3397
3398             if (isGcReliabilityFramework(scenario)) {
3399                 // runtest.sh doesn't actually execute the reliability framework - do it here.
3400                 if (useServerGC) {
3401                     if (runDocker) {
3402                         dockerCmd = dockerPrefix + "-e COMPlus_gcServer=1 ${dockerImage} "
3403                     }
3404                     else {
3405                         shell("export COMPlus_gcServer=1")
3406                     }
3407                 }
3408
3409                 shell("${dockerCmd}./tests/scripts/run-gc-reliability-framework.sh ${architecture} ${configuration}")
3410             }
3411         } // steps
3412     } // job
3413
3414     // Experimental: If on Ubuntu 14.04, then attempt to pull in crash dump links
3415     if (os in ['Ubuntu']) {
3416         SummaryBuilder summaries = new SummaryBuilder()
3417         summaries.addLinksSummaryFromFile('Crash dumps from this run:', 'dumplings.txt')
3418         summaries.emit(newJob)
3419     }
3420
3421     if (isPmiAsmDiffsScenario) {
3422         // Archive the asm
3423         Utilities.addArchival(newJob, "dasm.${os}.${architecture}.${configuration}.zip")
3424     }
3425     else if (doCoreFxTesting) {
3426         Utilities.addArchival(newJob, "${workspaceRelativeFxRootLinux}/artifacts/bin/**/testResults.xml")
3427         if ((os == "Ubuntu") && (architecture == 'arm')) {
3428             // We have a problem with the xunit plug-in, where it is consistently failing on Ubuntu arm32 test result uploading with this error:
3429             //
3430             //   [xUnit] [ERROR] - The plugin hasn't been performed correctly: remote file operation failed: /ssd/j/workspace/dotnet_coreclr/master/jitstress/arm_cross_checked_ubuntu_corefx_baseline_tst at hudson.remoting.Channel@3697f46d:JNLP4-connect connection from 131.107.159.149/131.107.159.149:58529: java.io.IOException: Remote call on JNLP4-connect connection from 131.107.159.149/131.107.159.149:58529 failed
3431             //
3432             // We haven't been able to identify the reason. So, do not add xunit parsing of the test data in this scenario.
3433             // This is tracked by: https://github.com/dotnet/coreclr/issues/19447.
3434         }
3435         else {
3436             Utilities.addXUnitDotNETResults(newJob, "${workspaceRelativeFxRootLinux}/artifacts/bin/**/testResults.xml")
3437         }
3438     }
3439     else {
3440         Utilities.addXUnitDotNETResults(newJob, '**/coreclrtests.xml')
3441     }
3442
3443     return newJob
3444 }
3445
3446 def static CreateNonWindowsCrossGenComparisonTestJob(def dslFactory, def project, def architecture, def os, def configuration, def scenario, def isPR, def inputCoreCLRBuildName)
3447 {
3448     assert isCrossGenComparisonScenario(scenario)
3449
3450     def osGroup = getOSGroup(os)
3451     def jobName = getJobName(configuration, architecture, os, scenario, false) + "_tst"
3452
3453     def workspaceRelativeResultsDir = "_"
3454     def workspaceRelativeNativeArchResultDir = "${workspaceRelativeResultsDir}/${osGroup}.${architecture}_${architecture}.${configuration}"
3455
3456     def crossArch = "x64"
3457     def workspaceRelativeCrossArchResultDir = "${workspaceRelativeResultsDir}/${osGroup}.${crossArch}_${architecture}.${configuration}"
3458
3459     def jobFolder = getJobFolder(scenario)
3460     def newJob = dslFactory.job(Utilities.getFullJobName(project, jobName, isPR, jobFolder)) {
3461         parameters {
3462             stringParam('CORECLR_BUILD', '', "Build number to copy CoreCLR ${osGroup} binaries from")
3463         }
3464
3465         def workspaceRelativeArtifactsArchive = "${os}.${architecture}.${configuration}.${scenario}.zip"
3466
3467         steps {
3468             copyArtifacts(inputCoreCLRBuildName) {
3469                 includePatterns("${workspaceRelativeArtifactsArchive}")
3470                 buildSelector {
3471                     buildNumber('${CORECLR_BUILD}')
3472                 }
3473             }
3474
3475             shell("unzip -o ${workspaceRelativeArtifactsArchive} || exit 0")
3476
3477             def workspaceRelativeCoreLib = "bin/Product/${osGroup}.${architecture}.${configuration}/IL/System.Private.CoreLib.dll"
3478             def workspaceRelativeCoreRootDir = "bin/tests/${osGroup}.${architecture}.${configuration}/Tests/Core_Root"
3479             def workspaceRelativeCrossGenComparisonScript = "tests/scripts/crossgen_comparison.py"
3480             def workspaceRelativeCrossGenExecutable = "${workspaceRelativeCoreRootDir}/crossgen"
3481
3482             def crossGenComparisonCmd = "python -u \${WORKSPACE}/${workspaceRelativeCrossGenComparisonScript} "
3483             def crossGenExecutable = "\${WORKSPACE}/${workspaceRelativeCrossGenExecutable}"
3484
3485             shell("mkdir -p ${workspaceRelativeNativeArchResultDir}")
3486             shell("${crossGenComparisonCmd}crossgen_corelib --crossgen ${crossGenExecutable} --il_corelib \${WORKSPACE}/${workspaceRelativeCoreLib} --result_dir \${WORKSPACE}/${workspaceRelativeNativeArchResultDir}")
3487             shell("${crossGenComparisonCmd}crossgen_framework --crossgen ${crossGenExecutable} --core_root \${WORKSPACE}/${workspaceRelativeCoreRootDir} --result_dir \${WORKSPACE}/${workspaceRelativeNativeArchResultDir}")
3488
3489             shell("${crossGenComparisonCmd}compare --base_dir \${WORKSPACE}/${workspaceRelativeNativeArchResultDir} --diff_dir \${WORKSPACE}/${workspaceRelativeCrossArchResultDir}")
3490         } // steps
3491     }  // job
3492
3493     Utilities.addArchival(newJob, "${workspaceRelativeNativeArchResultDir}/**")
3494     Utilities.addArchival(newJob, "${workspaceRelativeCrossArchResultDir}/**")
3495
3496     return newJob
3497 }
3498
3499 // Create a test job that will be used by a flow job.
3500 // Returns the newly created job.
3501 // Note that we don't add tests jobs to the various views, since they are always used by a flow job, which is in the views,
3502 // and we want the views to be the minimal set of "top-level" jobs that represent all work.
3503 def static CreateTestJob(def dslFactory, def project, def branch, def architecture, def os, def configuration, def scenario, def isPR, def inputCoreCLRBuildName)
3504 {
3505     def windowsArmJob = ((os == "Windows_NT") && (architecture in Constants.armWindowsCrossArchitectureList))
3506
3507     def newJob = null
3508     if (windowsArmJob) {
3509         newJob = CreateWindowsArmTestJob(dslFactory, project, architecture, os, configuration, scenario, isPR, inputCoreCLRBuildName)
3510     }
3511     else if (isCrossGenComparisonScenario(scenario)) {
3512         newJob = CreateNonWindowsCrossGenComparisonTestJob(dslFactory, project, architecture, os, configuration, scenario, isPR, inputCoreCLRBuildName)
3513     }
3514     else {
3515         newJob = CreateOtherTestJob(dslFactory, project, branch, architecture, os, configuration, scenario, isPR, inputCoreCLRBuildName)
3516     }
3517
3518     setJobMachineAffinity(architecture, os, false, true, false, newJob) // isBuildJob = false, isTestJob = true, isFlowJob = false
3519
3520     if (scenario == 'jitdiff') {
3521         def osGroup = getOSGroup(os)
3522         Utilities.addArchival(newJob, "bin/tests/${osGroup}.${architecture}.${configuration}/dasm/**")
3523     }
3524
3525     Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
3526     setJobTimeout(newJob, isPR, architecture, configuration, scenario, false)
3527
3528     return newJob
3529 }
3530
3531 // Create a flow job to tie together a build job with the given test job.
3532 // Returns the new flow job.
3533 def static CreateFlowJob(def dslFactory, def project, def branch, def architecture, def os, def configuration, def scenario, def isPR, def fullTestJobName, def inputCoreCLRBuildName)
3534 {
3535     // Windows CoreCLR build and Linux CoreCLR build (in parallel) ->
3536     // Linux CoreCLR test
3537     def flowJobName = getJobName(configuration, architecture, os, scenario, false) + "_flow"
3538     def jobFolder = getJobFolder(scenario)
3539
3540     def newFlowJob = dslFactory.buildFlowJob(Utilities.getFullJobName(project, flowJobName, isPR, jobFolder)) {
3541         buildFlow("""\
3542 coreclrBuildJob = build(params, '${inputCoreCLRBuildName}')
3543
3544 // And then build the test build
3545 build(params + [CORECLR_BUILD: coreclrBuildJob.build.number], '${fullTestJobName}')
3546 """)
3547     }
3548     JobReport.Report.addReference(inputCoreCLRBuildName)
3549     JobReport.Report.addReference(fullTestJobName)
3550
3551     addToViews(newFlowJob, true, isPR, architecture, os, configuration, scenario) // isFlowJob = true
3552
3553     setJobMachineAffinity(architecture, os, false, false, true, newFlowJob) // isBuildJob = false, isTestJob = false, isFlowJob = true
3554
3555     Utilities.standardJobSetup(newFlowJob, project, isPR, "*/${branch}")
3556     addTriggers(newFlowJob, branch, isPR, architecture, os, configuration, scenario, true, false) // isFlowJob==true, isWindowsBuildOnlyJob==false
3557
3558     return newFlowJob
3559 }
3560
3561 // Determine if we should generate a flow job for the given parameters.
3562 // Returns true if the job should be generated.
3563 def static shouldGenerateFlowJob(def scenario, def isPR, def architecture, def configuration, def os)
3564 {
3565     // The various "innerloop" jobs are only available as PR triggered.
3566
3567     if (!isPR) {
3568         if (isInnerloopTestScenario(scenario)) {
3569             return false
3570         }
3571
3572         if (scenario == 'corefx_innerloop') {
3573             return false
3574         }
3575     }
3576
3577     // Filter based on OS and architecture.
3578
3579     switch (architecture) {
3580         case 'arm':
3581             if (os != "Ubuntu" && os != "Windows_NT") {
3582                 return false
3583             }
3584             break
3585         case 'arm64':
3586             if (os != "Ubuntu16.04" && os != "Windows_NT") {
3587                 return false
3588             }
3589             break
3590         case 'x86':
3591             if (os != "Ubuntu") {
3592                 return false
3593             }
3594             break
3595         case 'x64':
3596             if (!(os in Constants.crossList)) {
3597                 return false
3598             }
3599             if (os == "Windows_NT") {
3600                 return false
3601             }
3602             break
3603         case 'armem':
3604             // No flow jobs
3605             return false
3606         default:
3607             println("Unknown architecture: ${architecture}")
3608             assert false
3609             break
3610     }
3611
3612     def isNormalOrInnerloop = (scenario == 'innerloop' || scenario == 'normal')
3613
3614     // Filter based on scenario in OS.
3615
3616     if (os == 'Windows_NT') {
3617         assert architecture == 'arm' || architecture == 'arm64'
3618         if (!isArmWindowsScenario(scenario)) {
3619             return false
3620         }
3621         if (isNormalOrInnerloop && (configuration == 'Debug')) {
3622             // The arm32/arm64 Debug configuration for innerloop/normal scenario is a special case: it does a build only, and no test run.
3623             // To do that, it doesn't require a flow job.
3624             return false
3625         }
3626     }
3627     else {
3628         // Non-Windows
3629         if (architecture == 'arm') {
3630             if (!(scenario in Constants.validLinuxArmScenarios)) {
3631                 return false
3632             }
3633         }
3634         else if (architecture == 'arm64') {
3635             if (!(scenario in Constants.validLinuxArm64Scenarios)) {
3636                 return false
3637             }
3638         }
3639         else if (architecture == 'x86') {
3640             // Linux/x86 only want innerloop and default test
3641             if (!isNormalOrInnerloop) {
3642                 return false
3643             }
3644         }
3645         else if (architecture == 'x64') {
3646             // Linux/x64 corefx testing doesn't need a flow job; the "build" job runs run-corefx-tests.py which
3647             // builds and runs the corefx tests. Other Linux/x64 flow jobs are required to get the test
3648             // build from a Windows machine.
3649             if (isCoreFxScenario(scenario)) {
3650                 return false
3651             }
3652         }
3653     }
3654
3655     // For CentOS, we only want Checked/Release builds.
3656     if (os == 'CentOS7.1') {
3657         if (configuration != 'Checked' && configuration != 'Release') {
3658             return false
3659         }
3660         if (!isNormalOrInnerloop && !isR2RScenario(scenario)) {
3661             return false
3662         }
3663     }
3664
3665     // For RedHat and Debian, we only do Release builds.
3666     else if (os == 'RHEL7.2' || os == 'Debian8.4') {
3667         if (configuration != 'Release') {
3668             return false
3669         }
3670         if (!isNormalOrInnerloop) {
3671             return false
3672         }
3673     }
3674
3675     // Next, filter based on scenario.
3676
3677     if (isJitStressScenario(scenario)) {
3678         if (configuration != 'Checked') {
3679             return false
3680         }
3681     }
3682     else if (isR2RBaselineScenario(scenario)) {
3683         if (configuration != 'Checked' && configuration != 'Release') {
3684             return false
3685         }
3686     }
3687     else if (isR2RStressScenario(scenario)) {
3688         if (configuration != 'Checked') {
3689             return false
3690         }
3691     }
3692     else if (isCrossGenComparisonScenario(scenario)) {
3693         return shouldGenerateCrossGenComparisonJob(os, architecture, configuration, scenario)
3694     }
3695     else {
3696         // Skip scenarios
3697         switch (scenario) {
3698             case 'ilrt':
3699             case 'longgc':
3700             case 'gcsimulator':
3701                 // Long GC tests take a long time on non-Release builds
3702                 // ilrt is also Release only
3703                 if (configuration != 'Release') {
3704                     return false
3705                 }
3706                 break
3707
3708             case 'jitdiff':
3709                 if (configuration != 'Checked') {
3710                     return false
3711                 }
3712                 break
3713
3714             case 'gc_reliability_framework':
3715             case 'standalone_gc':
3716                 if (configuration != 'Release' && configuration != 'Checked') {
3717                     return false
3718                 }
3719                 break
3720
3721             case 'formatting':
3722                 return false
3723
3724             case 'illink':
3725                 if (os != 'Windows_NT' && os != 'Ubuntu') {
3726                     return false
3727                 }
3728                 break
3729
3730             case 'normal':
3731                 // Nothing skipped
3732                 break
3733
3734             case 'innerloop':
3735                 if (!isValidPrTriggeredInnerLoopJob(os, architecture, configuration, false)) {
3736                     return false
3737                 }
3738                 break
3739
3740             case 'pmi_asm_diffs':
3741                 if (configuration != 'Checked') {
3742                     return false
3743                 }
3744                 // No need for flow job except for Linux arm/arm64
3745                 if ((os != 'Windows_NT') && (architecture != 'arm') && (architecture != 'arm64')) {
3746                     return false
3747                 }
3748                 break
3749
3750             case 'corefx_innerloop':
3751                 // No flow job needed
3752                 return false
3753
3754             default:
3755                 println("Unknown scenario: ${scenario}")
3756                 assert false
3757                 break
3758         }
3759     }
3760
3761     // The job was not filtered out, so we should generate it!
3762     return true
3763 }
3764
3765 // Create jobs requiring flow jobs. This includes x64 non-Windows, arm/arm64 Ubuntu, and arm/arm64 Windows.
3766 Constants.allScenarios.each { scenario ->
3767     [true, false].each { isPR ->
3768         Constants.architectureList.each { architecture ->
3769             Constants.configurationList.each { configuration ->
3770                 Constants.osList.each { os ->
3771
3772                     if (!shouldGenerateFlowJob(scenario, isPR, architecture, configuration, os)) {
3773                         return
3774                     }
3775
3776                     def windowsArmJob = ((os == "Windows_NT") && (architecture in Constants.armWindowsCrossArchitectureList))
3777                     def doCoreFxTesting = isCoreFxScenario(scenario)
3778                     def doCrossGenComparison = isCrossGenComparisonScenario(scenario)
3779                     def isPmiAsmDiffsScenario = (scenario == 'pmi_asm_diffs')
3780
3781                     // Figure out the job name of the CoreCLR build the test will depend on.
3782
3783                     def inputCoreCLRBuildScenario = isInnerloopTestScenario(scenario) ? 'innerloop' : 'normal'
3784                     def inputCoreCLRBuildIsBuildOnly = false
3785                     if (doCoreFxTesting || isPmiAsmDiffsScenario) {
3786                         // Every CoreFx test depends on its own unique build.
3787                         inputCoreCLRBuildScenario = scenario
3788                         if (windowsArmJob) {
3789                             // Only Windows ARM corefx jobs use "build only" jobs. Others, such as Ubuntu ARM corefx, use "regular" jobs.
3790                             inputCoreCLRBuildIsBuildOnly = true
3791                         }
3792                     }
3793                     else if (doCrossGenComparison) {
3794                         inputCoreCLRBuildScenario = scenario
3795                     }
3796
3797                     def inputCoreCLRFolderName = getJobFolder(inputCoreCLRBuildScenario)
3798                     def inputCoreCLRBuildName = projectFolder + '/' +
3799                         Utilities.getFullJobName(project, getJobName(configuration, architecture, os, inputCoreCLRBuildScenario, inputCoreCLRBuildIsBuildOnly), isPR, inputCoreCLRFolderName)
3800
3801                     // =============================================================================================
3802                     // Create the test job
3803                     // =============================================================================================
3804
3805                     def testJob = CreateTestJob(this, project, branch, architecture, os, configuration, scenario, isPR, inputCoreCLRBuildName)
3806
3807                     // =============================================================================================
3808                     // Create a build flow to join together the build and tests required to run this test.
3809                     // =============================================================================================
3810
3811                     if (os == 'RHEL7.2' || os == 'Debian8.4') {
3812                         // Do not create the flow job for RHEL jobs.
3813                         return
3814                     }
3815
3816                     def fullTestJobName = projectFolder + '/' + testJob.name
3817                     def flowJob = CreateFlowJob(this, project, branch, architecture, os, configuration, scenario, isPR, fullTestJobName, inputCoreCLRBuildName)
3818
3819                 } // os
3820             } // configuration
3821         } // architecture
3822     } // isPR
3823 } // scenario
3824
3825 JobReport.Report.generateJobReport(out)
3826
3827 // Make the call to generate the help job
3828 Utilities.createHelperJob(this, project, branch,
3829     "Welcome to the ${project} Repository",  // This is prepended to the help message
3830     "Have a nice day!")  // This is appended to the help message.  You might put known issues here.
3831
3832 Utilities.addCROSSCheck(this, project, branch)