Merge pull request #5807 from Maoni0/obj_addr
[platform/upstream/coreclr.git] / netci.groovy
1 // Import the utility functionality.
2
3 import jobs.generation.Utilities;
4 import jobs.generation.JobReport;
5
6 // The input project name (e.g. dotnet/coreclr)
7 def project = GithubProject
8 // The input branch name (e.g. master)
9 def branch = GithubBranchName
10 def projectFolder = Utilities.getFolderName(project) + '/' + Utilities.getFolderName(branch)
11                        
12 def static getOSGroup(def os) {
13     def osGroupMap = ['Ubuntu':'Linux',
14         'RHEL7.2': 'Linux',
15         'Ubuntu16.04': 'Linux',
16         'Debian8.4':'Linux',
17         'Fedora23':'Linux',
18         'OSX':'OSX',
19         'Windows_NT':'Windows_NT',
20         'FreeBSD':'FreeBSD',
21         'CentOS7.1': 'Linux',
22         'OpenSUSE13.2': 'Linux',
23         'LinuxARMEmulator': 'Linux']
24     def osGroup = osGroupMap.get(os, null) 
25     assert osGroup != null : "Could not find os group for ${os}"
26     return osGroupMap[os]
27 }
28
29 // We use this class (vs variables) so that the static functions can access data here.
30 class Constants {
31     // Innerloop build OS's
32     // The Windows_NT_BuildOnly OS is a way to speed up the Non-NT builds temporarily by avoiding
33     // test execution in the build flow runs.  It generates the exact same build
34     // as Windows_NT but without the tests.
35     def static osList = ['Ubuntu', 'Debian8.4', 'OSX', 'Windows_NT', 'Windows_NT_BuildOnly', 'FreeBSD', 'CentOS7.1', 'OpenSUSE13.2', 'RHEL7.2', 'LinuxARMEmulator', 'Ubuntu16.04', 'Fedora23']
36     def static crossList = ['Ubuntu', 'OSX', 'CentOS7.1', 'RHEL7.2', 'Debian8.4', 'OpenSUSE13.2']
37     // This is a set of JIT stress modes combined with the set of variables that
38     // need to be set to actually enable that stress mode.  The key of the map is the stress mode and
39     // the values are the environment variables
40     def static jitStressModeScenarios = ['minopts' : ['COMPlus_JITMinOpts' : '1'], 'forcerelocs' : ['COMPlus_ForceRelocs' : '1'],
41                'jitstress1' : ['COMPlus_JitStress' : '1'], 'jitstress2' : ['COMPlus_JitStress' : '2'],
42                'jitstressregs1' : ['COMPlus_JitStressRegs' : '1'], 'jitstressregs2' : ['COMPlus_JitStressRegs' : '2'],
43                'jitstressregs3' : ['COMPlus_JitStressRegs' : '3'], 'jitstressregs4' : ['COMPlus_JitStressRegs' : '4'],
44                'jitstressregs8' : ['COMPlus_JitStressRegs' : '8'], 'jitstressregs0x10' : ['COMPlus_JitStressRegs' : '0x10'],
45                'jitstressregs0x80' : ['COMPlus_JitStressRegs' : '0x80'],
46                'jitstress2_jitstressregs1'    : ['COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '1'],
47                'jitstress2_jitstressregs2'    : ['COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '2'],
48                'jitstress2_jitstressregs3'    : ['COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '3'],
49                'jitstress2_jitstressregs4'    : ['COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '4'],
50                'jitstress2_jitstressregs8'    : ['COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '8'],
51                'jitstress2_jitstressregs0x10' : ['COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '0x10'],
52                'jitstress2_jitstressregs0x80' : ['COMPlus_JitStress' : '2', 'COMPlus_JitStressRegs' : '0x80'],
53                'corefx_baseline' : [ : ], // corefx baseline
54                'corefx_minopts' : ['COMPlus_JITMinOpts' : '1'],
55                'corefx_jitstress1' : ['COMPlus_JitStress' : '1'], 
56                'corefx_jitstress2' : ['COMPlus_JitStress' : '2'],
57                'corefx_jitstressregs1' : ['COMPlus_JitStressRegs' : '1'], 'corefx_jitstressregs2' : ['COMPlus_JitStressRegs' : '2'],
58                'corefx_jitstressregs3' : ['COMPlus_JitStressRegs' : '3'], 'corefx_jitstressregs4' : ['COMPlus_JitStressRegs' : '4'],
59                'corefx_jitstressregs8' : ['COMPlus_JitStressRegs' : '8'], 'corefx_jitstressregs0x10' : ['COMPlus_JitStressRegs' : '0x10'],
60                'corefx_jitstressregs0x80' : ['COMPlus_JitStressRegs' : '0x80'],
61                'gcstress0x3' : ['COMPlus_GCStress'  : '0x3'], 'gcstress0xc' : ['COMPlus_GCStress'  : '0xC'],
62                'zapdisable' : ['COMPlus_ZapDisable'  : '0xC'],
63                'heapverify1' : ['COMPlus_HeapVerify'  : '1'],
64                'gcstress0xc_zapdisable' : ['COMPlus_GCStress'  : '0xC', 'COMPlus_ZapDisable'  : '1'],
65                'gcstress0xc_zapdisable_jitstress2' : ['COMPlus_GCStress'  : '0xC', 'COMPlus_ZapDisable'  : '1', 'COMPlus_JitStress'  : '2'],
66                'gcstress0xc_zapdisable_heapverify1' : ['COMPlus_GCStress'  : '0xC', 'COMPlus_ZapDisable'  : '1', 'COMPlus_HeapVerify'  : '1'],
67                'gcstress0xc_jitstress1' : ['COMPlus_GCStress'  : '0xC', 'COMPlus_JitStress'  : '1'],
68                'gcstress0xc_jitstress2' : ['COMPlus_GCStress'  : '0xC', 'COMPlus_JitStress'  : '2'],
69                'gcstress0xc_minopts_heapverify1' : ['COMPlus_GCStress'  : '0xC', 'COMPlus_JITMinOpts'  : '1', 'COMPlus_HeapVerify'  : '1']
70                ]
71     // This is a set of r2r jit stress scenarios
72     def static r2rJitStressScenarios = ['r2r_jitstress1', 'r2r_jitstress2', 'r2r_jitstressregs1', 'r2r_jitstressregs2', 'r2r_jitstressregs3',
73                                         'r2r_jitstressregs4', 'r2r_jitstressregs8', 'r2r_jitstressregsx10', 'r2r_jitstressregsx80',
74                                         'r2r_jitminopts', 'r2r_jitforcerelocs']
75     // This is the basic set of scenarios
76     def static basicScenarios = ['default', 'pri1', 'ilrt', 'r2r', 'pri1r2r', 'gcstress15_pri1r2r', 'longgc', 'coverage', 'gcsimulator'] + r2rJitStressScenarios
77     def static configurationList = ['Debug', 'Checked', 'Release']
78     // This is the set of architectures
79     def static architectureList = ['arm', 'arm64', 'x64', 'x86ryujit', 'x86lb']
80 }
81
82 def static setMachineAffinity(def job, def os, def architecture) {
83     if (architecture == 'arm64' && os == 'Windows_NT') {
84         // For cross compilation
85         job.with {
86             label('arm64')
87         }
88     } else if ((architecture == 'arm' || architecture == 'arm64') && os == 'Ubuntu') {
89         Utilities.setMachineAffinity(job, os, 'arm-cross-latest');
90     } else {
91         Utilities.setMachineAffinity(job, os, 'latest-or-auto');
92     }
93 }
94
95 def static isGCStressRelatedTesting(def scenario) {
96     // The 'gcstress15_pri1r2r' scenario is a basic scenario.
97     // Detect it and make it a GCStress related.
98     if (scenario == 'gcstress15_pri1r2r')
99     {
100         return true;
101     }
102
103     def gcStressTestEnvVars = [ 'COMPlus_GCStress', 'COMPlus_ZapDisable', 'COMPlus_HeapVerify']
104     def scenarioName = scenario.toLowerCase()
105     def isGCStressTesting = false
106     Constants.jitStressModeScenarios[scenario].each{ k, v -> 
107         if (k in gcStressTestEnvVars) {
108             isGCStressTesting = true;
109         }
110     }   
111     return isGCStressTesting
112 }
113
114 def static isCorefxTesting(def scenario) {
115     def corefx_prefix = 'corefx_'
116     if (scenario.length() < corefx_prefix.length()) {
117         return false
118     }
119     return scenario.substring(0,corefx_prefix.length()) == corefx_prefix
120 }
121
122 def static isR2R(def scenario) {
123     return (scenario == 'r2r' || scenario == 'pri1r2r')
124 }
125
126 def static isCoverage(def scenario) {
127     return (scenario == 'coverage')
128 }
129
130 def static isLongGc(def scenario) {
131     return (scenario == 'longgc' || scenario == 'gcsimulator')
132 }
133
134 def static setTestJobTimeOut(newJob, scenario) {
135     if (isGCStressRelatedTesting(scenario)) {
136         Utilities.setJobTimeout(newJob, 4320)
137     }
138     else if (isCorefxTesting(scenario)) {
139         Utilities.setJobTimeout(newJob, 360)
140     }
141     else if (Constants.jitStressModeScenarios.containsKey(scenario)) {
142         Utilities.setJobTimeout(newJob, 240)
143     }
144     else if (isR2R(scenario)) {
145         Utilities.setJobTimeout(newJob, 240)
146     }
147     else if (isCoverage(scenario)) {
148         Utilities.setJobTimeout(newJob, 1440)  
149     }
150     else if (isLongGc(scenario)) {
151         Utilities.setJobTimeout(newJob, 1440)
152     }
153     // Non-test jobs use the default timeout value.
154 }
155
156 def static getStressModeDisplayName(def scenario) {
157     def displayStr = ''
158     Constants.jitStressModeScenarios[scenario].each{ k, v -> 
159         def prefixLength = 'COMPlus_'.length()
160         if (k.length() >= prefixLength) {
161             def modeName = k.substring(prefixLength, k.length())
162             displayStr += ' ' + modeName + '=' + v
163         }
164     }   
165     return displayStr
166 }
167
168 // Generates the string for creating a file that sets environment variables
169 // that makes it possible to run stress modes.  Writes the script to a file called
170 // SetStressModes.[sh/cmd]
171 def static genStressModeScriptStep(def os, def stressModeName, def stressModeVars, def stepScriptLocation) {
172     def stepScript = ''
173     if (os == 'Windows_NT') {
174         stepScript += "echo Creating TestEnv Script for ${stressModeName}\r\n"
175         stepScript += "del ${stepScriptLocation}\r\n"
176         stressModeVars.each{ k, v -> 
177             // Write out what we are writing to the script file
178             stepScript += "echo Setting ${k}=${v}\r\n"
179             // Write out the set itself to the script file`
180             stepScript += "echo set ${k}=${v} >> ${stepScriptLocation}\r\n"
181         }
182     }
183     else {
184         stepScript += "echo Setting variables for ${stressModeName}\n"
185         stepScript += "echo \\#\\!/usr/bin/env bash > ${stepScriptLocation}\n"
186         stressModeVars.each{ k, v -> 
187             // Write out what we are writing to the script file
188             stepScript += "echo Setting ${k}=${v}\n"
189             // Write out the set itself to the script file`
190             stepScript += "echo export ${k}=${v} >> ${stepScriptLocation}\n"
191         }
192         stepScript += "chmod +x ${stepScriptLocation}\n"
193     }
194     return stepScript
195 }
196
197 // Corefx doesn't have a support to pass stress mode environment variables. This function
198 // generates commands to set or export environment variables
199 def static getStressModeEnvSetCmd(def os, def stressModeName) {
200     def envVars = Constants.jitStressModeScenarios[stressModeName]
201     def setEnvVars = ''
202     if (os == 'Windows_NT') {
203         envVars.each{ VarName, Value   ->
204             if (VarName != '') {
205                 setEnvVars += "set ${VarName}=${Value}\n"
206             }
207         }
208     }
209     else {
210         envVars.each{ VarName, Value   ->
211             if (VarName != '') {
212                 setEnvVars += "export ${VarName}=${Value}\n"
213             }
214         }
215     }
216     return setEnvVars
217 }
218
219 // Calculates the name of the build job based on some typical parameters.
220 //
221 def static getJobName(def configuration, def architecture, def os, def scenario, def isBuildOnly) {
222     // If the architecture is x64, do not add that info into the build name.
223     // Need to change around some systems and other builds to pick up the right builds
224     // to do that.
225     
226     def suffix = scenario != 'default' ? "_${scenario}" : '';
227     if (isBuildOnly) {
228         suffix += '_bld'
229     }
230     def baseName = ''
231     switch (architecture) {
232         case 'x64':
233             if (scenario == 'default') {
234                 // For now we leave x64 off of the name for compatibility with other jobs
235                 baseName = configuration.toLowerCase() + '_' + os.toLowerCase()
236             }
237             else {
238                 baseName = architecture.toLowerCase() + '_' + configuration.toLowerCase() + '_' + os.toLowerCase()
239             }
240             break
241         case 'arm64':
242         case 'arm':
243             // These are cross builds
244             baseName = architecture.toLowerCase() + '_cross_' + configuration.toLowerCase() + '_' + os.toLowerCase()
245             break
246         case 'x86ryujit':
247             baseName = 'x86_ryujit_' + configuration.toLowerCase() + '_' + os.toLowerCase()
248             break
249         case 'x86lb':
250             baseName = 'x86_lb_' + configuration.toLowerCase() + '_' + os.toLowerCase()
251             break
252         default:
253             println("Unknown architecture: ${architecture}");
254             assert false
255             break
256     }
257     
258     return baseName + suffix
259 }
260
261 static void addEmailPublisher(def job, def recipient) {
262     job.with {
263         publishers {
264             extendedEmail(recipient, '$DEFAULT_SUBJECT', '$DEFAULT_CONTENT') {
265                 trigger('Aborted', '$PROJECT_DEFAULT_SUBJECT', '$PROJECT_DEFAULT_CONTENT', null, true, true, true, true)
266                 trigger('Failure', '$PROJECT_DEFAULT_SUBJECT', '$PROJECT_DEFAULT_CONTENT', null, true, true, true, true)
267             }
268         }
269     }
270 }
271
272 // **************************
273 // Define the basic inner loop builds for PR and commit.  This is basically just the set
274 // of coreclr builds over linux/osx/freebsd/windows and debug/release/checked.  In addition, the windows
275 // builds will do a couple extra steps.
276 // **************************
277
278 // Adds a trigger for the PR build if one is needed.  If isFlowJob is true, then this is the
279 // flow job that rolls up the build and test for non-windows OS's.  // If the job is a windows build only job,
280 // it's just used for internal builds
281 // If you add a job with a trigger phrase, please add that phrase to coreclr/Documentation/project-docs/ci-trigger-phrases.md
282 def static addTriggers(def job, def branch, def isPR, def architecture, def os, def configuration, def scenario, def isFlowJob, def isWindowsBuildOnlyJob, def isLinuxEmulatorBuild) {
283     if (isWindowsBuildOnlyJob) {
284         return
285     }
286     
287     def bidailyCrossList = ['RHEL7.2', 'Debian8.4', 'OpenSUSE13.2']
288     // Non pull request builds.
289     if (!isPR) {
290         // Check scenario.
291         switch (scenario) {
292             case 'default':
293                 switch (architecture) {
294                     case 'x64':
295                     case 'x86ryujit':
296                     case 'x86lb':
297                         if (isFlowJob || os == 'Windows_NT' || !(os in Constants.crossList)) {
298                             Utilities.addGithubPushTrigger(job)
299                         }
300                         break
301                     case 'arm':
302                         Utilities.addGithubPushTrigger(job)
303                         break
304                     case 'arm64':
305                         if (os == 'Windows_NT') {
306                             Utilities.addGithubPushTrigger(job)
307                             addEmailPublisher(job, 'dotnetonarm64@microsoft.com')
308                         }
309                         break
310                     default:
311                         println("Unknown architecture: ${architecture}");
312                         assert false
313                         break
314                 }
315                 break
316             case 'pri1':
317                 // Pri one gets a push trigger, and only for release
318                 if (architecture == 'x64') {
319                     if (configuration == 'Release') {
320                         // We expect release jobs to be Windows, or in the cross list
321                         assert (os == 'Windows_NT') || (os in Constants.crossList)
322                         if (!os in bidailyCrossList) {
323                             if (isFlowJob || os == 'Windows_NT') {
324                                 Utilities.addGithubPushTrigger(job)
325                             }
326                         } 
327                         else {
328                             if (isFlowJob) {
329                                 Utilities.addPeriodicTrigger(job, 'H H/12 * * *')
330                             }
331                         }
332                     }
333                 }
334                 break
335             case 'r2r':
336                 //r2r jobs that aren't pri1 can only be triggered by phrase
337                 break
338             case 'pri1r2r':
339                 assert !(os in bidailyCrossList)
340                 //pri1 r2r gets a push trigger for checked/release
341                 if (configuration == 'Checked' || configuration == 'Release') {
342                     assert (os == 'Windows_NT') || (os in Constants.crossList)
343                     if (architecture == 'x64' && os != 'OSX') {
344                         //Flow jobs should be Windows, Ubuntu, OSX, or CentOS
345                         if (isFlowJob || os == 'Windows_NT') {
346                             Utilities.addGithubPushTrigger(job)
347                         }
348                     // OSX pri1r2r jobs should only run every 12 hours, not daily.
349                     } else if (architecture == 'x64' && os == 'OSX'){
350                         if (isFlowJob) {
351                             Utilities.addPeriodicTrigger(job, 'H H/12 * * *')
352                         }
353                     }
354                     // For x86, only add per-commit jobs for Windows
355                     else if (architecture == 'x86ryujit' || architecture == 'x86lb') {
356                         if (os == 'Windows_NT') {
357                             Utilities.addGithubPushTrigger(job)
358                         }
359                     }
360                     // arm64 pri1r2r jobs should only run every 12 hours.
361                     else if (architecture == 'arm64') {
362                         if (os == 'Windows_NT') {
363                             Utilities.addPeriodicTrigger(job, 'H H/12 * * *')
364                             addEmailPublisher(job, 'dotnetonarm64@microsoft.com')
365                         }
366                     }
367                 }
368                 break
369             case 'r2r_jitstress1':
370             case 'r2r_jitstress2':
371             case 'r2r_jitstressregs1':
372             case 'r2r_jitstressregs2':
373             case 'r2r_jitstressregs3':
374             case 'r2r_jitstressregs4':
375             case 'r2r_jitstressregs8':
376             case 'r2r_jitstressregsx10':
377             case 'r2r_jitstressregsx80':
378             case 'r2r_jitminopts':
379             case 'r2r_jitforcerelocs':
380             case 'gcstress15_pri1r2r':
381                 assert !(os in bidailyCrossList)
382                 //GC Stress 15 pri1 r2r gets a push trigger for checked/release
383                 if (configuration == 'Checked' || configuration == 'Release') {
384                     assert (os == 'Windows_NT') || (os in Constants.crossList)
385                     if (architecture == 'x64') {
386                         //Flow jobs should be Windows, Ubuntu, OSX, or CentOS
387                         if (isFlowJob || os == 'Windows_NT') {
388                             // Add a weekly periodic trigger
389                             Utilities.addPeriodicTrigger(job, 'H H * * 3,6') // some time every Wednesday and Saturday
390                         }
391                     }
392                     // For x86, only add per-commit jobs for Windows
393                     else if (architecture == 'x86ryujit' || architecture == 'x86lb') {
394                         if (os == 'Windows_NT') {
395                             Utilities.addPeriodicTrigger(job, 'H H * * 3,6') // some time every Wednesday and Saturday
396                         }
397                     }
398                 }
399                 break
400             case 'longgc':
401                 assert (os == 'Ubuntu' || os == 'Windows_NT' || os == 'OSX')
402                 assert configuration == 'Release'
403                 assert architecture == 'x64'
404                 Utilities.addPeriodicTrigger(job, '@daily')
405                 addEmailPublisher(job, 'dotnetgctests@microsoft.com')
406                 break
407             case 'gcsimulator':
408                 assert (os == 'Ubuntu' || os == 'Windows_NT' || os == 'OSX')
409                 assert configuration == 'Release'
410                 assert architecture == 'x64'
411                 Utilities.addPeriodicTrigger(job, 'H H * * 3,6') // some time every Wednesday and Saturday
412                 addEmailPublisher(job, 'dotnetgctests@microsoft.com')
413                 break
414             case 'ilrt':
415                 assert !(os in bidailyCrossList)
416                 // ILASM/ILDASM roundtrip one gets a daily build, and only for release
417                 if (architecture == 'x64' && configuration == 'Release') {
418                     // We don't expect to see a job generated except in these scenarios
419                     assert (os == 'Windows_NT') || (os in Constants.crossList)
420                     if (isFlowJob || os == 'Windows_NT') {
421                         Utilities.addPeriodicTrigger(job, '@daily')
422                     }
423                 }
424                 break
425             case 'coverage':
426                 assert (os == 'Ubuntu' || os == 'Windows_NT')
427                 assert configuration == 'Release'
428                 assert architecture == 'x64'
429                 Utilities.addPeriodicTrigger(job, '@weekly')
430                 break
431             case 'jitstressregs1':
432             case 'jitstressregs2':
433             case 'jitstressregs3':
434             case 'jitstressregs4':
435             case 'jitstressregs8':
436             case 'jitstressregs0x10':
437             case 'jitstressregs0x80':
438             case 'minopts':
439             case 'forcerelocs':
440             case 'jitstress1':
441             case 'jitstress2':   
442             case 'jitstress2_jitstressregs1':
443             case 'jitstress2_jitstressregs2':
444             case 'jitstress2_jitstressregs3':
445             case 'jitstress2_jitstressregs4':
446             case 'jitstress2_jitstressregs8':
447             case 'jitstress2_jitstressregs0x10':
448             case 'jitstress2_jitstressregs0x80':
449             case 'corefx_baseline': 
450             case 'corefx_minopts':
451             case 'corefx_jitstress1':               
452             case 'corefx_jitstress2':
453             case 'corefx_jitstressregs1':
454             case 'corefx_jitstressregs2':
455             case 'corefx_jitstressregs3':
456             case 'corefx_jitstressregs4':
457             case 'corefx_jitstressregs8':
458             case 'corefx_jitstressregs0x10':
459             case 'corefx_jitstressregs0x80':
460             case 'zapdisable':           
461                 if (os != 'CentOS7.1' && !(os in bidailyCrossList)) {
462                     assert (os == 'Windows_NT') || (os in Constants.crossList)
463                     Utilities.addPeriodicTrigger(job, '@daily')
464                 }
465                 break            
466             case 'gcstress0x3':            
467             case 'gcstress0xc':
468             case 'heapverify1':
469             case 'gcstress0xc_zapdisable':
470             case 'gcstress0xc_zapdisable_jitstress2':
471             case 'gcstress0xc_zapdisable_heapverify1':
472             case 'gcstress0xc_jitstress1':
473             case 'gcstress0xc_jitstress2':
474             case 'gcstress0xc_minopts_heapverify1':       
475                 if (os != 'CentOS7.1' && !(os in bidailyCrossList)) {
476                     assert (os == 'Windows_NT') || (os in Constants.crossList)
477                     Utilities.addPeriodicTrigger(job, '@weekly')
478                 }
479                 break
480             default:
481                 println("Unknown scenario: ${scenario}");
482                 assert false
483                 break
484         }
485         return
486     }
487     // Pull request builds.  Generally these fall into two categories: default triggers and on-demand triggers
488     // We generally only have a distinct set of default triggers but a bunch of on-demand ones.
489     def osGroup = getOSGroup(os)
490     switch (architecture) {
491         case 'x64':
492             if (scenario == 'coverage') {
493                 assert configuration == 'Release'
494                 if (os == 'Ubuntu') {
495                     Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Coverage Build & Test", "(?i).*test\\W+coverage.*")
496                 }
497                 break
498             }
499             switch (os) {
500                 // OpenSUSE, Debian & RedHat get trigger phrases for pri 0 build, and pri 1 build & test
501                 case 'OpenSUSE13.2':
502                 case 'Debian8.4':
503                 case 'RHEL7.2':
504                     if (scenario == 'default') {
505                         assert !isFlowJob
506                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build", "(?i).*test\\W+${os}.*")
507                     }
508                     else if (scenario == 'pri1' && isFlowJob) {
509                         assert (configuration == 'Release')
510                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Pri 1 Build & Test", "(?i).*test\\W+${os}\\W+${scenario}.*")
511                     }
512                     break
513                 case 'Fedora23':
514                 case 'Ubuntu16.04':
515                     assert !isFlowJob
516                     assert scenario == 'default'
517                     Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build", '(?i).*test\\W+${os}\\W+.*')
518                     break                
519                 case 'Ubuntu':
520                 case 'OSX':
521                     // Triggers on the non-flow jobs aren't necessary here
522                     // Corefx testing uses non-flow jobs.
523                     if (!isFlowJob && !isCorefxTesting(scenario)) {
524                         break
525                     }
526                     switch (scenario) {
527                         case 'default':
528                             // Ubuntu uses checked for default PR tests
529                             if (configuration == 'Checked') {
530                                 // Default trigger
531                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test")
532                             }
533                             break
534                         case 'pri1':
535                             if (configuration == 'Release') {
536                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Priority 1 Build and Test", "(?i).*test\\W+${os}\\W+${scenario}.*")
537                             }
538                             break
539                         case 'ilrt':
540                             if (configuration == 'Release') {
541                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} IL RoundTrip Build and Test", "(?i).*test\\W+${os}\\W+${scenario}.*")
542                             }
543                             break
544                         case 'r2r':
545                             if (configuration == 'Release' || configuration == 'Checked') {
546                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} R2R pri0 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
547                             }
548                             break
549                         case 'pri1r2r':
550                             if (configuration == 'Release' || configuration == 'Checked') {
551                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} R2R pri1 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
552                             }
553                             break
554                         case 'gcstress15_pri1r2r':
555                             if (configuration == 'Release' || configuration == 'Checked') {
556                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} GCStress 15 R2R pri1 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
557                             }
558                             break
559                         case 'r2r_jitstress1':
560                             if (configuration == 'Release' || configuration == 'Checked') {
561                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstress1 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
562                             }
563                             break
564                         case 'r2r_jitstress2':
565                             if (configuration == 'Release' || configuration == 'Checked') {
566                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstress2 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
567                             }
568                             break
569                         case 'r2r_jitstressregs1':
570                             if (configuration == 'Release' || configuration == 'Checked') {
571                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregs1 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
572                             }
573                             break
574                         case 'r2r_jitstressregs2':
575                             if (configuration == 'Release' || configuration == 'Checked') {
576                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregs2 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
577                             }
578                             break
579                         case 'r2r_jitstressregs3':
580                             if (configuration == 'Release' || configuration == 'Checked') {
581                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregs3 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
582                             }
583                             break
584                         case 'r2r_jitstressregs4':
585                             if (configuration == 'Release' || configuration == 'Checked') {
586                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregs4 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
587                             }
588                             break
589                         case 'r2r_jitstressregs8':
590                             if (configuration == 'Release' || configuration == 'Checked') {
591                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregs8 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
592                             }
593                             break
594                         case 'r2r_jitstressregsx10':
595                             if (configuration == 'Release' || configuration == 'Checked') {
596                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregsx10 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
597                             }
598                             break
599                         case 'r2r_jitstressregsx80':
600                             if (configuration == 'Release' || configuration == 'Checked') {
601                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregsx80 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
602                             }
603                             break
604                         case 'r2r_jitminopts':
605                             if (configuration == 'Release' || configuration == 'Checked') {
606                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} JITMinOpts R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
607                             }
608                             break
609                         case 'r2r_jitforcerelocs':
610                             if (configuration == 'Release' || configuration == 'Checked') {
611                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} ForceRelocs R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
612                             }
613                             break
614                         case 'longgc':
615                             if (configuration == 'Release') {
616                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Long-Running GC Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
617                             }
618                             break
619                         case 'gcsimulator':
620                             if (configuration == 'Release') {
621                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} GC Simulator", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
622                             }
623                             break
624                         case 'minopts':
625                             assert (os == 'Windows_NT') || (os in Constants.crossList)
626                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - MinOpts)",
627                                "(?i).*test\\W+${os}\\W+${scenario}.*")
628                             break
629                         case 'jitstress1':
630                             assert (os == 'Windows_NT') || (os in Constants.crossList)
631                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStress=1)",
632                                "(?i).*test\\W+${os}\\W+${scenario}.*")
633                             break
634                         case 'jitstress2':
635                             assert (os == 'Windows_NT') || (os in Constants.crossList)
636                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStress=2)",
637                                "(?i).*test\\W+${os}\\W+${scenario}.*")
638                             break                           
639                         case 'forcerelocs':
640                             assert (os == 'Windows_NT') || (os in Constants.crossList)
641                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - ForceRelocs)",
642                                "(?i).*test\\W+${os}\\W+${scenario}.*")
643                         case 'jitstressregs1':
644                             assert (os == 'Windows_NT') || (os in Constants.crossList)
645                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStressRegs=1)",
646                                "(?i).*test\\W+${os}\\W+${scenario}.*")
647                             break                           
648                         case 'jitstressregs2':
649                             assert (os == 'Windows_NT') || (os in Constants.crossList)
650                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStressRegs=2)",
651                                "(?i).*test\\W+${os}\\W+${scenario}.*")
652                             break                                                   
653                         case 'jitstressregs3':
654                             assert (os == 'Windows_NT') || (os in Constants.crossList)
655                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStressRegs=3)",
656                                "(?i).*test\\W+${os}\\W+${scenario}.*")
657                             break                                                   
658                         case 'jitstressregs4':      
659                             assert (os == 'Windows_NT') || (os in Constants.crossList)
660                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStressRegs=4)",
661                                "(?i).*test\\W+${os}\\W+${scenario}.*")
662                             break                                                   
663                         case 'jitstressregs8':
664                             assert (os == 'Windows_NT') || (os in Constants.crossList)
665                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStressRegs=8)",
666                                "(?i).*test\\W+${os}\\W+${scenario}.*")
667                             break
668                         case 'jitstressregs0x10':
669                             assert (os == 'Windows_NT') || (os in Constants.crossList)
670                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStressRegs=0x10)",
671                                "(?i).*test\\W+${os}\\W+${scenario}.*")
672                             break
673                         case 'jitstressregs0x80':
674                             assert (os == 'Windows_NT') || (os in Constants.crossList)
675                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStressRegs=0x80)",
676                                "(?i).*test\\W+${os}\\W+${scenario}.*")
677                             break
678                         case 'jitstress2_jitstressregs1':
679                         case 'jitstress2_jitstressregs2':
680                         case 'jitstress2_jitstressregs3':
681                         case 'jitstress2_jitstressregs4':
682                         case 'jitstress2_jitstressregs8':
683                         case 'jitstress2_jitstressregs0x10':
684                         case 'jitstress2_jitstressregs0x80':
685                         case 'gcstress0x3':
686                         case 'gcstress0xc':
687                         case 'zapdisable':
688                         case 'heapverify1':
689                         case 'gcstress0xc_zapdisable':
690                         case 'gcstress0xc_zapdisable_jitstress2':
691                         case 'gcstress0xc_zapdisable_heapverify1':
692                         case 'gcstress0xc_jitstress1':
693                         case 'gcstress0xc_jitstress2':
694                         case 'gcstress0xc_minopts_heapverify1':                                 
695                             def displayStr = getStressModeDisplayName(scenario)  
696                             assert (os == 'Windows_NT') || (os in Constants.crossList)
697                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - ${displayStr})",
698                                "(?i).*test\\W+${os}\\W+${scenario}.*")
699                             break
700                         case 'corefx_baseline':
701                         case 'corefx_minopts':
702                         case 'corefx_jitstress1':
703                         case 'corefx_jitstress2':
704                         case 'corefx_jitstressregs1':
705                         case 'corefx_jitstressregs2':
706                         case 'corefx_jitstressregs3':
707                         case 'corefx_jitstressregs4':
708                         case 'corefx_jitstressregs8':
709                         case 'corefx_jitstressregs0x10':
710                         case 'corefx_jitstressregs0x80':
711                             def displayName = 'CoreFx' + getStressModeDisplayName(scenario)                                                    
712                             assert (os == 'Windows_NT') || (os in Constants.crossList)
713                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - ${displayName})",
714                                "(?i).*test\\W+${os}\\W+${scenario}.*")
715                             break                          
716                         default:
717                             println("Unknown scenario: ${scenario}");
718                             assert false
719                             break
720                     }
721                     break
722                 case 'CentOS7.1':
723                     switch (scenario) {
724                         case 'pri1':
725                             if (configuration == 'Release') {
726                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Priority 1 Build and Test", "(?i).*test\\W+${os}\\W+${scenario}.*")
727                             }
728                             break
729                         case 'r2r':
730                             if (configuration == 'Checked' || configuration == 'Release') {
731                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} R2R pri0 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
732                             }
733                             break
734                         case 'pri1r2r':
735                             if (configuration == 'Checked' || configuration == 'Release') {
736                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} R2R pri1 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
737                             }
738                             break
739                         case 'gcstress15_pri1r2r':
740                             if (configuration == 'Release' || configuration == 'Checked') {
741                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} GCStress 15 R2R pri1 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
742                             }
743                             break
744                         case 'r2r_jitstress1':
745                             if (configuration == 'Release' || configuration == 'Checked') {
746                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstress1 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
747                             }
748                             break
749                         case 'r2r_jitstress2':
750                             if (configuration == 'Release' || configuration == 'Checked') {
751                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstress2 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
752                             }
753                             break
754                         case 'r2r_jitstressregs1':
755                             if (configuration == 'Release' || configuration == 'Checked') {
756                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregs1 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
757                             }
758                             break
759                         case 'r2r_jitstressregs2':
760                             if (configuration == 'Release' || configuration == 'Checked') {
761                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregs2 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
762                             }
763                             break
764                         case 'r2r_jitstressregs3':
765                             if (configuration == 'Release' || configuration == 'Checked') {
766                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregs3 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
767                             }
768                             break
769                         case 'r2r_jitstressregs4':
770                             if (configuration == 'Release' || configuration == 'Checked') {
771                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregs4 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
772                             }
773                             break
774                         case 'r2r_jitstressregs8':
775                             if (configuration == 'Release' || configuration == 'Checked') {
776                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregs8 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
777                             }
778                             break
779                         case 'r2r_jitstressregsx10':
780                             if (configuration == 'Release' || configuration == 'Checked') {
781                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregsx10 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
782                             }
783                             break
784                         case 'r2r_jitstressregsx80':
785                             if (configuration == 'Release' || configuration == 'Checked') {
786                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregsx80 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
787                             }
788                             break
789                         case 'r2r_jitminopts':
790                             if (configuration == 'Release' || configuration == 'Checked') {
791                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} JITMinOpts R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
792                             }
793                             break
794                         case 'r2r_jitforcerelocs':
795                             if (configuration == 'Release' || configuration == 'Checked') {
796                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} ForceRelocs R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
797                             }
798                             break
799                         default:
800                             break
801                     }   
802                 case 'Windows_NT':
803                     switch (scenario) {
804                         case 'default':
805                             // Default trigger
806                             if (configuration == 'Debug') {
807                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test")
808                             }
809                             break
810                         case 'pri1':
811                             // Default trigger
812                             if (configuration == 'Release') {
813                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Priority 1 Build and Test")
814                             }
815                             break
816                         case 'ilrt':
817                             if (configuration == 'Release') {
818                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} IL RoundTrip Build and Test", "(?i).*test\\W+${os}\\W+${scenario}.*")
819                             }
820                             break
821                         case 'r2r':
822                             if (configuration == 'Checked' || configuration == 'Release') {
823                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} R2R pri0 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
824                             }
825                             break
826                         case 'pri1r2r':
827                             if (configuration == 'Checked' || configuration == 'Release') {
828                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} R2R pri1 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
829                             }
830                             break
831                         case 'gcstress15_pri1r2r':
832                             if (configuration == 'Release' || configuration == 'Checked') {
833                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} GCStress 15 R2R pri1 Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
834                             }
835                             break
836                         case 'r2r_jitstress1':
837                             if (configuration == 'Release' || configuration == 'Checked') {
838                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstress1 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
839                             }
840                             break
841                         case 'r2r_jitstress2':
842                             if (configuration == 'Release' || configuration == 'Checked') {
843                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstress2 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
844                             }
845                             break
846                         case 'r2r_jitstressregs1':
847                             if (configuration == 'Release' || configuration == 'Checked') {
848                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregs1 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
849                             }
850                             break
851                         case 'r2r_jitstressregs2':
852                             if (configuration == 'Release' || configuration == 'Checked') {
853                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregs2 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
854                             }
855                             break
856                         case 'r2r_jitstressregs3':
857                             if (configuration == 'Release' || configuration == 'Checked') {
858                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregs3 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
859                             }
860                             break
861                         case 'r2r_jitstressregs4':
862                             if (configuration == 'Release' || configuration == 'Checked') {
863                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregs4 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
864                             }
865                             break
866                         case 'r2r_jitstressregs8':
867                             if (configuration == 'Release' || configuration == 'Checked') {
868                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregs8 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
869                             }
870                             break
871                         case 'r2r_jitstressregsx10':
872                             if (configuration == 'Release' || configuration == 'Checked') {
873                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregsx10 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
874                             }
875                             break
876                         case 'r2r_jitstressregsx80':
877                             if (configuration == 'Release' || configuration == 'Checked') {
878                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} jitstressregsx80 R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
879                             }
880                             break
881                         case 'r2r_jitminopts':
882                             if (configuration == 'Release' || configuration == 'Checked') {
883                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} JITMinOpts R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
884                             }
885                             break
886                         case 'r2r_jitforcerelocs':
887                             if (configuration == 'Release' || configuration == 'Checked') {
888                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} ForceRelocs R2R Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")  
889                             }
890                             break
891                         case 'longgc':
892                             if (configuration == 'Release') {
893                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Long-Running GC Build & Test", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
894                             }
895                             break
896                         case 'gcsimulator':
897                             if (configuration == 'Release') {
898                                 Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} GC Simulator", "(?i).*test\\W+${os}\\W+${configuration}\\W+${scenario}.*")
899                             }
900                             break
901                         case 'minopts':
902                             assert (os == 'Windows_NT') || (os in Constants.crossList)
903                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - MinOpts)",
904                                "(?i).*test\\W+${os}\\W+${scenario}.*")
905                             break
906                         case 'forcerelocs':                         
907                             assert (os == 'Windows_NT') || (os in Constants.crossList)
908                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - ForceRelocs)",
909                                "(?i).*test\\W+${os}\\W+${scenario}.*")
910                             break                           
911                         case 'jitstress1':
912                             assert (os == 'Windows_NT') || (os in Constants.crossList)
913                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStress=1)",
914                                "(?i).*test\\W+${os}\\W+${scenario}.*")
915                             break
916                         case 'jitstress2':
917                             assert (os == 'Windows_NT') || (os in Constants.crossList)
918                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStress=2)",
919                                "(?i).*test\\W+${os}\\W+${scenario}.*")
920                             break
921                         case 'jitstressregs1':
922                             assert (os == 'Windows_NT') || (os in Constants.crossList)
923                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStressRegs=1)",
924                                "(?i).*test\\W+${os}\\W+${scenario}.*")
925                             break                       
926                         case 'jitstressregs2':
927                             assert (os == 'Windows_NT') || (os in Constants.crossList)
928                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStressRegs=2)",
929                                "(?i).*test\\W+${os}\\W+${scenario}.*")
930                             break                       
931                         case 'jitstressregs3':
932                             assert (os == 'Windows_NT') || (os in Constants.crossList)
933                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStressRegs=3)",
934                                "(?i).*test\\W+${os}\\W+${scenario}.*")
935                             break                       
936                         case 'jitstressregs4':      
937                             assert (os == 'Windows_NT') || (os in Constants.crossList)
938                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStressRegs=4)",
939                                "(?i).*test\\W+${os}\\W+${scenario}.*")
940                             break                       
941                         case 'jitstressregs8':
942                             assert (os == 'Windows_NT') || (os in Constants.crossList)
943                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStressRegs=8)",
944                                "(?i).*test\\W+${os}\\W+${scenario}.*")
945                             break                       
946                         case 'jitstressregs0x10':
947                             assert (os == 'Windows_NT') || (os in Constants.crossList)
948                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStressRegs=0x10)",
949                                "(?i).*test\\W+${os}\\W+${scenario}.*")
950                             break                       
951                         case 'jitstressregs0x80':
952                             assert (os == 'Windows_NT') || (os in Constants.crossList)
953                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - JitStressRegs=0x80)",
954                                "(?i).*test\\W+${os}\\W+${scenario}.*")
955                             break       
956                         case 'jitstress2_jitstressregs1':
957                         case 'jitstress2_jitstressregs2':
958                         case 'jitstress2_jitstressregs3':
959                         case 'jitstress2_jitstressregs4':
960                         case 'jitstress2_jitstressregs8':
961                         case 'jitstress2_jitstressregs0x10':
962                         case 'jitstress2_jitstressregs0x80':
963                         case 'gcstress0x3': 
964                         case 'gcstress0xc':
965                         case 'zapdisable':
966                         case 'heapverify1':
967                         case 'gcstress0xc_zapdisable':
968                         case 'gcstress0xc_zapdisable_jitstress2':
969                         case 'gcstress0xc_zapdisable_heapverify1':
970                         case 'gcstress0xc_jitstress1':
971                         case 'gcstress0xc_jitstress2':
972                         case 'gcstress0xc_minopts_heapverify1':                                 
973                             def displayStr = getStressModeDisplayName(scenario)
974                             assert (os == 'Windows_NT') || (os in Constants.crossList)
975                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - ${displayStr})",
976                                "(?i).*test\\W+${os}\\W+${scenario}.*")
977                             break                                   
978                         case 'corefx_baseline':
979                         case 'corefx_minopts':
980                         case 'corefx_jitstress1':
981                         case 'corefx_jitstress2':
982                         case 'corefx_jitstressregs1':
983                         case 'corefx_jitstressregs2':
984                         case 'corefx_jitstressregs3':
985                         case 'corefx_jitstressregs4':
986                         case 'corefx_jitstressregs8':
987                         case 'corefx_jitstressregs0x10':
988                         case 'corefx_jitstressregs0x80':
989                             def displayName = 'CoreFx ' + getStressModeDisplayName(scenario)
990                             assert (os == 'Windows_NT') || (os in Constants.crossList)
991                             Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build and Test (Jit - ${displayName})",
992                                "(?i).*test\\W+${os}\\W+${scenario}.*")
993                             break                       
994                         default:
995                             println("Unknown scenario: ${scenario}");
996                             assert false
997                             break
998                     }
999                     break
1000                 case 'FreeBSD':
1001                     assert scenario == 'default'
1002                     if (configuration == 'Checked') {
1003                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} ${configuration} Build")
1004                     }
1005                     break
1006                 default:
1007                     println("Unknown os: ${os}");
1008                     assert false
1009                     break
1010             }
1011             break
1012         case 'arm':
1013             assert scenario == 'default'
1014             switch (os) {
1015                 case 'Ubuntu':
1016                     if (!isLinuxEmulatorBuild) {
1017                         // Removing the regex will cause this to run on each PR.
1018                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${architecture} Cross ${configuration} Build")
1019                     }
1020                     else {
1021                         Utilities.addGithubPRTriggerForBranch(job, branch, "Linux ARM Emulator Build", "(?i).*test\\W+Linux\\W+arm\\W+emulator.*")
1022                     }
1023                     break
1024                 default:
1025                     println("NYI os: ${os}");
1026                     assert false
1027                     break
1028             }
1029             break
1030         case 'arm64':
1031             assert (scenario == 'default') || (scenario == 'pri1r2r')
1032
1033             // Set up a private trigger
1034             def contextString = "${os} ${architecture} Cross ${configuration}"
1035             if (scenario != 'default')
1036                 contextString += " ${scenario}"
1037             contextString += " Build"
1038             // Debug builds only.
1039             if (configuration != 'Debug') {
1040                contextString += " and Test"
1041             }
1042
1043             def arm64Users = ['erozenfeld', 'kyulee1', 'pgavlin', 'russellhadley', 'swaroop-sridhar', 'JosephTremoulet', 'jashook', 'RussKeldorph', 'gkhanna79', 'briansull', 'cmckinsey', 'jkotas', 'ramarag', 'markwilkie', 'rahku', 'tzwlai', 'weshaggard']
1044             switch (os) {
1045                 case 'Windows_NT':
1046                     switch (scenario) {
1047                         case 'default':
1048                             Utilities.addPrivateGithubPRTriggerForBranch(job, branch, contextString,
1049                             "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}", null, arm64Users)
1050                             break
1051                         case 'pri1r2r':
1052                             Utilities.addPrivateGithubPRTriggerForBranch(job, branch, contextString,
1053                             "(?i).*test\\W+${os}\\W+${architecture}\\W+${configuration}\\W+${scenario}", null, arm64Users)
1054                             break
1055                     }
1056                     break
1057                 default:
1058                     println("NYI os: ${os}");
1059                     assert false
1060                     break
1061             }
1062             break
1063         case 'x86ryujit':
1064         case 'x86lb':
1065             assert (scenario == 'default' || scenario == 'r2r' || scenario == 'pri1r2r' || scenario == 'gcstress15_pri1r2r' || scenario == 'longgc' || scenario == 'gcsimulator' ||
1066                     Constants.r2rJitStressScenarios.indexOf(scenario) != -1)
1067             // For windows, x86 runs by default
1068             def arch = 'x86'
1069             def jit = 'ryujit'
1070             if (architecture == 'x86lb') {
1071                 jit = 'legacy_backend'
1072             }
1073             
1074             if (scenario == 'default') {
1075                 if (os == 'Windows_NT') {
1076                     if (configuration == 'Checked') {
1077                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} Build and Test")
1078                     }
1079                 }
1080                 else {
1081                     // default trigger
1082                     Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} Build", "(?i).*test\\W+${arch}\\W+${osGroup}.\\W+${jit}*")
1083                 }
1084             }
1085             else if (scenario == 'r2r') {
1086                 if (os == 'Windows_NT') {
1087                     if (configuration == 'Release') {
1088                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} R2R pri0 Build & Test", "(?i).*test\\W+${os}\\W+${arch}\\W+${jit}\\W+${configuration}\\W+${scenario}.*")
1089                     }
1090                 }
1091             }
1092             else if (scenario == 'pri1r2r') {
1093                 if (os == 'Windows_NT') {
1094                     if (configuration == 'Release') {
1095                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} R2R pri1 Build & Test", "(?i).*test\\W+${os}\\W+${arch}\\W+${jit}\\W+${configuration}\\W+${scenario}.*")
1096                     }
1097                 }
1098             }
1099             else if (scenario == 'gcstress15_pri1r2r'){
1100                 if (os == 'Windows_NT'){
1101                     if (configuration == 'Release'){
1102                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} GCStress 15 R2R pri1 Build & Test", "(?i).*test\\W+${os}\\W+${arch}\\W+${jit}\\W+${configuration}\\W+${scenario}.*")  
1103                     }
1104                 }
1105             }
1106             else if (scenario == 'r2r_jitstress1'){
1107                 if (configuration == 'Release' || configuration == 'Checked') {
1108                     if (os == 'Windows_NT'){
1109                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} jitstress1 R2R Build & Test", "(?i).*test\\W+${os}\\W+${arch}\\W+${jit}\\W+${configuration}\\W+${scenario}.*")  
1110                     }
1111                 }
1112             }
1113             else if (scenario == 'r2r_jitstress2'){
1114                 if (configuration == 'Release' || configuration == 'Checked') {
1115                     if (os == 'Windows_NT'){
1116                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} jitstress2 R2R Build & Test", "(?i).*test\\W+${os}\\W+${arch}\\W+${jit}\\W+${configuration}\\W+${scenario}.*")  
1117                     }
1118                 }
1119             }
1120             else if (scenario == 'r2r_jitstressregs1'){
1121                 if (configuration == 'Release' || configuration == 'Checked') {
1122                     if (os == 'Windows_NT'){
1123                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} jitstressregs1 R2R Build & Test", "(?i).*test\\W+${os}\\W+${arch}\\W+${jit}\\W+${configuration}\\W+${scenario}.*")  
1124                     }
1125                 }
1126             }
1127             else if (scenario == 'r2r_jitstressregs2'){
1128                 if (configuration == 'Release' || configuration == 'Checked') {
1129                     if (os == 'Windows_NT'){
1130                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} jitstressregs2 R2R Build & Test", "(?i).*test\\W+${os}\\W+${arch}\\W+${jit}\\W+${configuration}\\W+${scenario}.*")  
1131                     }
1132                 }
1133             }
1134             else if (scenario == 'r2r_jitstressregs3'){
1135                 if (configuration == 'Release' || configuration == 'Checked') {
1136                     if (os == 'Windows_NT'){
1137                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} jitstressregs3 R2R Build & Test", "(?i).*test\\W+${os}\\W+${arch}\\W+${jit}\\W+${configuration}\\W+${scenario}.*")  
1138                     }
1139                 }
1140             }
1141             else if (scenario == 'r2r_jitstressregs4'){
1142                 if (configuration == 'Release' || configuration == 'Checked') {
1143                     if (os == 'Windows_NT'){
1144                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} jitstressregs4 R2R Build & Test", "(?i).*test\\W+${os}\\W+${arch}\\W+${jit}\\W+${configuration}\\W+${scenario}.*")  
1145                     }
1146                 }
1147             }
1148             else if (scenario == 'r2r_jitstressregs8'){
1149                 if (configuration == 'Release' || configuration == 'Checked') {
1150                     if (os == 'Windows_NT'){
1151                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} jitstressregs8 R2R Build & Test", "(?i).*test\\W+${os}\\W+${arch}\\W+${jit}\\W+${configuration}\\W+${scenario}.*")  
1152                     }
1153                 }
1154             }
1155             else if (scenario == 'r2r_jitstressregsx10'){
1156                 if (configuration == 'Release' || configuration == 'Checked') {
1157                     if (os == 'Windows_NT'){
1158                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} jitstressregsx10 R2R Build & Test", "(?i).*test\\W+${os}\\W+${arch}\\W+${jit}\\W+${configuration}\\W+${scenario}.*")  
1159                     }
1160                 }
1161             }
1162             else if (scenario == 'r2r_jitstressregsx80'){
1163                 if (configuration == 'Release' || configuration == 'Checked') {
1164                     if (os == 'Windows_NT'){
1165                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} jitstressregsx80 R2R Build & Test", "(?i).*test\\W+${os}\\W+${arch}\\W+${jit}\\W+${configuration}\\W+${scenario}.*")  
1166                     }
1167                 }
1168             }
1169             else if (scenario == 'r2r_jitminopts'){
1170                 if (configuration == 'Release' || configuration == 'Checked') {
1171                     if (os == 'Windows_NT'){
1172                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} jitminopts R2R Build & Test", "(?i).*test\\W+${os}\\W+${arch}\\W+${jit}\\W+${configuration}\\W+${scenario}.*")  
1173                     }
1174                 }
1175             }
1176             else if (scenario == 'r2r_jitforcerelocs'){
1177                 if (configuration == 'Release' || configuration == 'Checked') {
1178                     if (os == 'Windows_NT'){
1179                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} jitforcerelocs R2R Build & Test", "(?i).*test\\W+${os}\\W+${arch}\\W+${jit}\\W+${configuration}\\W+${scenario}.*")  
1180                     }
1181                 }
1182             }
1183             else if (scenario == 'longgc') {
1184                 if (os == 'Windows_NT'){
1185                     if (configuration == 'Release'){
1186                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} Long-Running GC Build & Test", "(?i).*test\\W+${os}\\W+${arch}\\W+${jit}\\W+${configuration}\\W+${scenario}.*")  
1187                     }
1188                 }
1189             }
1190             else if (scenario == 'gcsimulator') {
1191                 if (os == 'Windows_NT') {
1192                     if (configuration == 'Release') {
1193                         Utilities.addGithubPRTriggerForBranch(job, branch, "${os} ${arch} ${jit} ${configuration} GC Simulator", "(?i).*test\\W+${os}\\W+${arch}\\W+${jit}\\W+${configuration}\\W+${scenario}.*")
1194                     }
1195                 }
1196             }
1197             break
1198         default:
1199             println("Unknown architecture: ${architecture}");
1200             assert false
1201             break
1202     }
1203 }
1204
1205 // Additional scenario which can alter behavior
1206
1207 def combinedScenarios = Constants.basicScenarios + Constants.jitStressModeScenarios.keySet()
1208 combinedScenarios.each { scenario ->
1209     [true, false].each { isPR ->
1210         Constants.architectureList.each { architecture ->
1211             Constants.configurationList.each { configuration ->
1212                 Constants.osList.each { os ->
1213                     // If the OS is Windows_NT_BuildOnly, set the isBuildOnly flag to true
1214                     // and reset the os to Windows_NT
1215                     def isBuildOnly = false
1216                     if (os == 'Windows_NT_BuildOnly') {
1217                         isBuildOnly = true
1218                         os = 'Windows_NT'
1219                     }
1220
1221                     // If the OS is LinuxARMEmulator and arch is arm, set the isLinuxEmulatorBuild
1222                     // flag to true and reset the os to Ubuntu
1223                     // The isLinuxEmulatorBuild flag will be used at a later time to execute the right
1224                     // set of build commands
1225                     // The tuples (LinuxARMEmulator, other architectures) are not handled and control returns
1226                     def isLinuxEmulatorBuild = false
1227                     if (os == 'LinuxARMEmulator' && architecture == 'arm') {
1228                         isLinuxEmulatorBuild = true
1229                         os = 'Ubuntu'
1230                     } else if (os == 'LinuxARMEmulator') {
1231                         return
1232                     }
1233
1234                     // Skip totally unimplemented (in CI) configurations.
1235                     switch (architecture) {
1236                         case 'arm64':
1237                             // Windows only
1238                             if (os != 'Windows_NT' || isBuildOnly) {
1239                                 return
1240                             }
1241                             break
1242                         case 'arm':
1243                             // Only Ubuntu cross implemented
1244                             if (os != 'Ubuntu') {
1245                                 return
1246                             }
1247                             break
1248                         case 'x86ryujit':
1249                         case 'x86lb':
1250                             // Skip non-windows
1251                             if (os != 'Windows_NT') {
1252                                 return
1253                             }
1254                             break
1255                         case 'x64':
1256                             // Everything implemented
1257                             break
1258                         default:
1259                             println("Unknown architecture: ${architecture}")
1260                             assert false
1261                             break
1262                     }
1263                     // Skip scenarios (blanket skipping for jit stress modes, which are good most everywhere
1264                     // with checked builds
1265                     def enableCorefxTesting = false
1266                     if (Constants.jitStressModeScenarios.containsKey(scenario)) {
1267                         if (configuration != 'Checked') {
1268                             return
1269                         }
1270                         
1271                         enableCorefxTesting = isCorefxTesting(scenario)
1272                         
1273                         // Since these are just execution time differences,
1274                         // skip platforms that don't execute the tests here (Windows_NT only)
1275                         def isEnabledOS = os == 'Windows_NT' || (os == 'Ubuntu' && enableCorefxTesting)
1276                         if (!isEnabledOS || isBuildOnly) {
1277                             return
1278                         }
1279                         
1280                         // No stress modes except on x64 right now (mainly because of bad test state on x86)
1281                         if (architecture != 'x64') {
1282                             return
1283                         }
1284                     }
1285                     else {
1286                         // If this is a r2r jitstress, jitstressregs, jitminopts or forcerelocs scenario
1287                         // and configuration is not Checked, bail out.
1288                         if (configuration != 'Checked' && Constants.r2rJitStressScenarios.indexOf(scenario) != -1) {
1289                             return;
1290                         }
1291
1292                         // Skip scenarios
1293                         switch (scenario) {
1294                             case 'pri1':
1295                                 // The pri1 build isn't necessary except for Windows_NT.  Non-Windows NT uses
1296                                 // the default scenario build
1297                                 if (os != 'Windows_NT') {
1298                                     return
1299                                 }
1300                                 // Only x64 for now
1301                                 if (architecture != 'x64') {
1302                                     return
1303                                 }
1304                                 break
1305                             case 'ilrt':
1306                                 // The ilrt build isn't necessary except for Windows_NT.  Non-Windows NT uses
1307                                 // the default scenario build
1308                                 if (os != 'Windows_NT') {
1309                                     return
1310                                 }
1311                                 // Only x64 for now
1312                                 if (architecture != 'x64') {
1313                                     return
1314                                 }
1315                                 break
1316                             case 'r2r':
1317                                 // The r2r build isn't necessary except for Windows_NT.  Non-Windows NT uses
1318                                 // the default scenario build
1319                                 if (os != 'Windows_NT') {
1320                                     return
1321                                 }
1322                                 if (architecture != 'x64') {
1323                                     return
1324                                 }
1325                                 break
1326                             case 'pri1r2r':
1327                                 // The pri1r2r build isn't necessary except for Windows_NT.  Non-Windows NT uses
1328                                 // the default scenario build
1329                                 if (os != 'Windows_NT') {
1330                                     return
1331                                 }
1332                                 if (architecture != 'x64') {
1333                                     if (architecture != 'arm64' || configuration == 'Debug') {
1334                                         return
1335                                     }
1336                                 }
1337                                 break
1338                             case 'gcstress15_pri1r2r':
1339                             case 'r2r_jitstress1':
1340                             case 'r2r_jitstress2':
1341                             case 'r2r_jitstressregs1':
1342                             case 'r2r_jitstressregs2':
1343                             case 'r2r_jitstressregs3':
1344                             case 'r2r_jitstressregs4':
1345                             case 'r2r_jitstressregs8':
1346                             case 'r2r_jitstressregsx10':
1347                             case 'r2r_jitstressregsx80':
1348                             case 'r2r_jitminopts':
1349                             case 'r2r_jitforcerelocs':
1350                                 // The above builds are not necessary except for Windows_NT.  Non-Windows NT uses
1351                                 // the default scenario build
1352                                 if (os != 'Windows_NT') {
1353                                     return
1354                                 }
1355                                 if (architecture != 'x64') {
1356                                     return
1357                                 }
1358                                 break
1359                             case 'longgc':
1360                             case 'gcsimulator':
1361                                 if (os != 'Windows_NT' && os != 'Ubuntu' && os != 'OSX') {
1362                                     return
1363                                 }
1364                                 if (architecture != 'x64') {
1365                                     return
1366                                 }
1367                                 if (configuration != 'Release') {
1368                                     return
1369                                 }
1370                                 break
1371                             // We need Windows & Ubuntu x64 Release bits for the code coverage build
1372                             case 'coverage':
1373                                 if (os != 'Windows_NT' && os != 'Ubuntu') {
1374                                     return
1375                                 }
1376                                 if (architecture != 'x64') {
1377                                     return
1378                                 }
1379                                 if (configuration != 'Release') {
1380                                     return
1381                                 }
1382                                 break
1383                             case 'default':
1384                                 // Nothing skipped
1385                                 break
1386                             default:
1387                                 println("Unknown scenario: ${scenario}")
1388                                 assert false
1389                                 break
1390                         }
1391                     }
1392                 
1393                     // Calculate names
1394                     def lowerConfiguration = configuration.toLowerCase()
1395                     def jobName = getJobName(configuration, architecture, os, scenario, isBuildOnly)
1396                     
1397                     // Create the new job
1398                     def newJob = job(Utilities.getFullJobName(project, jobName, isPR)) {}
1399
1400                     setMachineAffinity(newJob, os, architecture)
1401
1402                     // Add all the standard options
1403                     Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
1404                     addTriggers(newJob, branch, isPR, architecture, os, configuration, scenario, false, isBuildOnly, isLinuxEmulatorBuild)
1405                 
1406                     def buildCommands = [];
1407                     def osGroup = getOSGroup(os)
1408                 
1409                     // Calculate the build steps, archival, and xunit results
1410                     switch (os) {
1411                         case 'Windows_NT':
1412                             switch (architecture) {
1413                                 case 'x64':
1414                                 case 'x86ryujit':
1415                                 case 'x86lb':
1416                                     def arch = architecture
1417                                     if (architecture == 'x86ryujit' || architecture == 'x86lb') {
1418                                         arch = 'x86'
1419                                     }
1420                                     
1421                                     if (Constants.jitStressModeScenarios.containsKey(scenario) ||
1422                                             scenario == 'default' ||
1423                                             scenario == 'r2r' ||
1424                                             Constants.r2rJitStressScenarios.indexOf(scenario) != -1) {
1425                                         buildOpts = enableCorefxTesting ? 'skiptests' : ''
1426                                         buildCommands += "set __TestIntermediateDir=int&&build.cmd ${lowerConfiguration} ${arch} ${buildOpts}"
1427                                     }
1428
1429                                     // For Pri 1 tests, we must shorten the output test binary path names.
1430                                     // if __TestIntermediateDir is already set, buildtest.cmd will
1431                                     // output test binaries to that directory. If it is not set, the 
1432                                     // binaries are sent to a default directory whose name is about
1433                                     // 35 characters long.
1434
1435                                     else if (scenario == 'pri1' || scenario == 'pri1r2r' || scenario == 'gcstress15_pri1r2r'|| scenario == 'coverage') {
1436                                         buildCommands += "set __TestIntermediateDir=int&&build.cmd ${lowerConfiguration} ${arch} Priority 1"
1437                                     }
1438                                     else if (scenario == 'ilrt') {
1439                                         // First do the build with skiptests and then build the tests with ilasm roundtrip
1440                                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} skiptests"
1441                                         buildCommands += "set __TestIntermediateDir=int&&tests\\buildtest.cmd ${lowerConfiguration} ${arch} ilasmroundtrip"
1442                                     }
1443                                     else if (isLongGc(scenario)) {
1444                                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} skiptests"
1445                                         buildCommands += "set __TestIntermediateDir=int&&tests\\buildtest.cmd ${lowerConfiguration} ${arch}"
1446                                     }
1447                                     else {
1448                                         println("Unknown scenario: ${scenario}")
1449                                         assert false
1450                                     }
1451                                     
1452                                     // If we are running a stress mode, we should write out the set of key
1453                                     // value env pairs to a file at this point and then we'll pass that to runtest.cmd
1454
1455                                     if (!isBuildOnly) {
1456                                         //If this is a crossgen build, pass 'crossgen' to runtest.cmd
1457                                         def crossgenStr = ''
1458                                         def runcrossgentestsStr = ''
1459                                         def runjitstressStr = ''
1460                                         def runjitstressregsStr = ''
1461                                         def runjitmioptsStr = ''
1462                                         def runjitforcerelocsStr = ''
1463                                         def gcstressStr = ''
1464                                         def runtestArguments = ''
1465                                         def gcTestArguments = ''
1466
1467                                         if (scenario == 'r2r' ||
1468                                             scenario == 'pri1r2r' ||
1469                                             scenario == 'gcstress15_pri1r2r' ||
1470                                             Constants.r2rJitStressScenarios.indexOf(scenario) != -1) {
1471                                                 crossgenStr = 'crossgen'
1472                                                 runcrossgentestsStr = 'runcrossgentests'
1473                                             
1474                                                 if (scenario == 'r2r_jitstress1'){
1475                                                     runjitstressStr = 'jitstress 1'
1476                                                 }
1477                                                 else if (scenario == 'r2r_jitstress2') {
1478                                                     runjitstressStr = 'jitstress 2'
1479                                                 }
1480                                                 else if (scenario == 'r2r_jitstressregs1'){
1481                                                     runjitstressregsStr = 'jitstressregs 1'
1482                                                 }
1483                                                 else if (scenario == 'r2r_jitstressregs2') {
1484                                                     runjitstressregsStr = 'jitstressregs 2'
1485                                                 }
1486                                                 else if (scenario == 'r2r_jitstressregs3') {
1487                                                     runjitstressregsStr = 'jitstressregs 3'
1488                                                 }
1489                                                 else if (scenario == 'r2r_jitstressregs4') {
1490                                                     runjitstressregsStr = 'jitstressregs 4'
1491                                                 }
1492                                                 else if (scenario == 'r2r_jitstressregs8') {
1493                                                     runjitstressregsStr = 'jitstressregs 8'
1494                                                 }
1495                                                 else if (scenario == 'r2r_jitstressregsx10') {
1496                                                     runjitstressregsStr = 'jitstressregs x10'
1497                                                 }
1498                                                 else if (scenario == 'r2r_jitstressregsx80') {
1499                                                     runjitstressregsStr = 'jitstressregs x80'
1500                                                 }
1501                                                 else if (scenario == 'r2r_jitminopts') {
1502                                                     runjitmioptsStr = 'jitminopts'
1503                                                 }
1504                                                 else if (scenario == 'r2r_jitforcerelocs') {
1505                                                     runjitforcerelocsStr = 'jitforcerelocs'
1506                                                 }
1507                                         }
1508                                         if (scenario == 'gcstress15_pri1r2r')
1509                                         {
1510                                            gcstressStr = 'gcstresslevel 0xF'
1511                                         }
1512
1513                                         if (isLongGc(scenario)) {
1514                                             gcTestArguments = '${scenario} sequential'
1515                                         }
1516
1517                                         runtestArguments = "${lowerConfiguration} ${arch} ${gcstressStr} ${crossgenStr} ${runcrossgentestsStr} ${runjitstressStr} ${runjitstressregsStr} ${runjitmioptsStr} ${runjitforcerelocsStr} ${gcTestArguments}"
1518                                         if (Constants.jitStressModeScenarios.containsKey(scenario)) {
1519                                             if (enableCorefxTesting) {
1520                                                 // Sync to corefx repo
1521                                                 // Move coreclr files to a subdirectory, %workspace%/clr. Otherwise, corefx build 
1522                                                 // thinks that %workspace% is the project base directory.
1523                                                 buildCommands += "powershell new-item clr -type directory -force"
1524                                                 buildCommands += 'powershell foreach ($x in get-childitem -force) { if (\$x.name -ne \'clr\') { move-item $x clr }}'
1525                                                 buildCommands += "git clone https://github.com/dotnet/corefx fx"
1526                                                 
1527                                                 buildCommands += getStressModeEnvSetCmd(os, scenario);
1528                                                 
1529                                                 // Run corefx build and testing
1530                                                 buildCommands += "cd fx && call \"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat\" x86 && Build.cmd /p:ConfigurationGroup=Release  /p:BUILDTOOLS_OVERRIDE_RUNTIME=%WORKSPACE%\\clr\\bin\\Product\\Windows_NT.x64.Checked "                                                                                              
1531                                             }
1532                                             else {
1533                                                 def stepScriptLocation = "%WORKSPACE%\\bin\\tests\\SetStressModes.bat"
1534                                                 buildCommands += genStressModeScriptStep(os, scenario, Constants.jitStressModeScenarios[scenario], stepScriptLocation)
1535                                                 
1536                                                 // Run tests with the 
1537                                                 
1538                                                 buildCommands += "tests\\runtest.cmd ${runtestArguments} TestEnv ${stepScriptLocation}"
1539                                             }                                            
1540                                         }
1541                                         else if (architecture == 'x64') {
1542                                             buildCommands += "tests\\runtest.cmd ${runtestArguments}"
1543                                         }                                        
1544                                         else if (architecture == 'x86ryujit') {
1545                                             def testEnvLocation = "%WORKSPACE%\\tests\\x86\\ryujit_x86_testenv.cmd"
1546                                             
1547                                             buildCommands += "tests\\runtest.cmd ${runtestArguments} TestEnv ${testEnvLocation}"
1548                                         }
1549                                         else if (architecture == 'x86lb') {
1550                                             buildCommands += "tests\\runtest.cmd ${runtestArguments} Exclude0 x86_legacy_backend_issues.targets"
1551                                         }
1552                                     }
1553
1554                                     if (!enableCorefxTesting) {
1555                                         // Run the rest of the build    
1556                                         // Build the mscorlib for the other OS's
1557                                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} linuxmscorlib"
1558                                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} freebsdmscorlib"
1559                                         buildCommands += "build.cmd ${lowerConfiguration} ${arch} osxmscorlib"
1560                                     
1561                                         // Zip up the tests directory so that we don't use so much space/time copying
1562                                         // 10s of thousands of files around.
1563                                         buildCommands += "powershell -Command \"Add-Type -Assembly 'System.IO.Compression.FileSystem'; [System.IO.Compression.ZipFile]::CreateFromDirectory('.\\bin\\tests\\${osGroup}.${arch}.${configuration}', '.\\bin\\tests\\tests.zip')\"";
1564                                         
1565                                         if (!Constants.jitStressModeScenarios.containsKey(scenario)) {
1566                                             // For windows, pull full test results and test drops for x86/x64.
1567                                             // No need to pull for stress mode scenarios (downstream builds use the default scenario)
1568                                             Utilities.addArchival(newJob, "bin/Product/**,bin/tests/tests.zip")
1569                                         }
1570                                         
1571                                         if (!isBuildOnly) {
1572                                             if (architecture == 'x64' || !isPR) {
1573                                                 Utilities.addXUnitDotNETResults(newJob, 'bin/**/TestRun*.xml')
1574                                             }
1575                                             setTestJobTimeOut(newJob, scenario)
1576                                         }
1577                                     }
1578                                     else {
1579                                         // Archive only result xml files since corefx/bin/tests is very large around 10 GB.                                        
1580                                         // For windows, pull full test results and test drops for x86/x64
1581                                         Utilities.addArchival(newJob, "fx/bin/tests/**/testResults.xml")
1582                                         
1583                                         // Set timeout 
1584                                         setTestJobTimeOut(newJob, scenario)
1585                                         
1586                                         if (architecture == 'x64' || !isPR) {
1587                                             Utilities.addXUnitDotNETResults(newJob, 'fx/bin/tests/**/testResults.xml')
1588                                         }
1589                                     }
1590                                     
1591                                     break
1592                                 case 'arm64':
1593                                     assert (scenario == 'default') || (scenario == 'pri1r2r')
1594
1595                                     // Up the timeout for arm64 jobs.
1596                                     Utilities.setJobTimeout(newJob, 240);
1597
1598                                     // Debug runs take too long to run. So build job only.
1599                                     if (lowerConfiguration == "debug") {
1600                                        buildCommands += "set __TestIntermediateDir=int&&build.cmd ${lowerConfiguration} ${architecture} /toolset_dir C:\\ats2"
1601                                     }
1602                                     else {
1603                                        buildCommands += "set __TestIntermediateDir=int&&build.cmd skiptests ${lowerConfiguration} ${architecture} /toolset_dir C:\\ats2"
1604                                        // Test build and run are launched together.
1605                                        buildCommands += "Z:\\arm64\\common\\scripts\\arm64PostLauncher.cmd %WORKSPACE% ${architecture} ${lowerConfiguration} ${scenario}"
1606                                        Utilities.addXUnitDotNETResults(newJob, 'bin/tests/testResults.xml')
1607                                     }
1608
1609                                     // Add archival.
1610                                     Utilities.addArchival(newJob, "bin/Product/**")
1611                                     break
1612                                 default:
1613                                     println("Unknown architecture: ${architecture}");
1614                                     assert false
1615                                     break
1616                             }
1617                             break
1618                         case 'Ubuntu':
1619                         case 'Ubuntu16.04':
1620                         case 'Debian8.4':
1621                         case 'OSX':
1622                         case 'FreeBSD':
1623                         case 'CentOS7.1':
1624                         case 'RHEL7.2':
1625                         case 'OpenSUSE13.2':
1626                         case 'Fedora23':
1627                             switch (architecture) {
1628                                 case 'x64':
1629                                 case 'x86ryujit':
1630                                 case 'x86lb':
1631                                     def arch = architecture
1632                                     if (architecture == 'x86ryujit' || architecture == 'x86lb') {
1633                                         arch = 'x86'
1634                                     }
1635                                 
1636                                     if (!enableCorefxTesting) {
1637                                         // We run pal tests on all OS but generate mscorlib (and thus, nuget packages)
1638                                         // only on supported OS platforms.
1639                                         if ((os == 'FreeBSD') || (os == 'OpenSUSE13.2'))
1640                                         {
1641                                             buildCommands += "./build.sh skipmscorlib verbose ${lowerConfiguration} ${arch}"
1642                                         }
1643                                         else if (scenario == 'coverage')
1644                                         {
1645                                             assert os == 'Ubuntu'
1646                                             assert lowerConfiguration == 'release'
1647                                             buildCommands += "./build.sh coverage verbose ${lowerConfiguration} ${arch}"
1648
1649                                             // Remove folders from obj that we don't expect to be covered. May update this later.
1650                                             buildCommands += "rm -rf ./bin/obj/Linux.x64.Release/src/ToolBox"
1651                                             buildCommands += "rm -rf ./bin/obj/Linux.x64.Release/src/debug"
1652                                             buildCommands += "rm -rf ./bin/obj/Linux.x64.Release/src/ilasm"
1653                                             buildCommands += "rm -rf ./bin/obj/Linux.x64.Release/src/ildasm"
1654                                             buildCommands += "rm -rf ./bin/obj/Linux.x64.Release/src/dlls/dbgshim"
1655                                             buildCommands += "rm -rf ./bin/obj/Linux.x64.Release/src/dlls/mscordac"
1656                                             buildCommands += "rm -rf ./bin/obj/Linux.x64.Release/src/dlls/mscordbi"
1657                                         }
1658                                         else
1659                                         {
1660                                             buildCommands += "./build.sh verbose ${lowerConfiguration} ${arch}"
1661                                         }
1662                                         buildCommands += "src/pal/tests/palsuite/runpaltests.sh \${WORKSPACE}/bin/obj/${osGroup}.${arch}.${configuration} \${WORKSPACE}/bin/paltestout"
1663
1664                                         // Delete PAL test obj files after we run them, if this is a coverage job
1665                                         if (scenario == 'coverage') {
1666                                             buildCommands += "rm -rf ./bin/obj/Linux.x64.Release/src/pal/tests"
1667                                         }
1668                                     
1669                                         // Set time out
1670                                         setTestJobTimeOut(newJob, scenario)
1671                                         // Basic archiving of the build
1672                                         if (scenario == 'coverage')
1673                                         {
1674                                             Utilities.addArchival(newJob, "bin/Product/**,bin/obj/Linux.x64.Release/src/**")
1675                                         }
1676                                         else {
1677                                             Utilities.addArchival(newJob, "bin/Product/**,bin/obj/*/tests/**/*.dylib,bin/obj/*/tests/**/*.so")
1678                                         }
1679                                         // And pal tests
1680                                         Utilities.addXUnitDotNETResults(newJob, '**/pal_tests.xml')
1681                                     }
1682                                     else {
1683                                         // Corefx stress testing                                        
1684                                         assert os == 'Ubuntu'
1685                                         assert architecture == 'x64'
1686                                         assert lowerConfiguration == 'checked'
1687                                         
1688                                         // Build coreclr and move it to clr directory
1689                                         buildCommands += "./build.sh verbose ${lowerConfiguration} ${architecture}"
1690                                         buildCommands += "rm -rf .clr; mkdir .clr; mv * .clr; mv .git .clr; mv .clr clr"
1691                                         
1692                                         // Get corefx
1693                                         buildCommands += "git clone https://github.com/dotnet/corefx fx"
1694                                         
1695                                         // Set environment variable
1696                                         def setEnvVar = getStressModeEnvSetCmd(os, scenario)                                        
1697
1698                                         // Build and text corefx
1699                                         buildCommands += "rm -rf \$WORKSPACE/fx_home; mkdir \$WORKSPACE/fx_home"
1700                                         buildCommands += setEnvVar
1701                                         buildCommands += "cd fx; export HOME=\$WORKSPACE/fx_home; ./build.sh /p:ConfigurationGroup=Release /p:BUILDTOOLS_OVERRIDE_RUNTIME=\$WORKSPACE/clr/bin/Product/Linux.x64.Checked /p:Outerloop=true /p:TestWithLocalLibraries=true"  
1702
1703                                         // Archive and process test result
1704                                         Utilities.addArchival(newJob, "fx/bin/tests/**/testResults.xml")
1705                                         setTestJobTimeOut(newJob, scenario)
1706                                         Utilities.addXUnitDotNETResults(newJob, 'fx/bin/tests/**/testResults.xml')
1707                                     }
1708                                     break
1709                                 case 'arm64':
1710                                     // We don't run the cross build except on Ubuntu
1711                                     assert os == 'Ubuntu'
1712                                     
1713                                     buildCommands += """echo \"Using rootfs in /opt/aarch64-linux-gnu-root\"
1714                                         ROOTFS_DIR=/opt/aarch64-linux-gnu-root ./build.sh skipmscorlib arm64 cross verbose ${lowerConfiguration}"""
1715                                     
1716                                     // Basic archiving of the build, no pal tests
1717                                     Utilities.addArchival(newJob, "bin/Product/**")
1718                                     break
1719                                 case 'arm':
1720                                     // All builds for ARM architecture are run on Ubuntu currently
1721                                     assert os == 'Ubuntu'
1722                                     if (!isLinuxEmulatorBuild) {
1723                                         buildCommands += """echo \"Using rootfs in /opt/arm-liux-genueabihf-root\"
1724                                             ROOTFS_DIR=/opt/arm-linux-genueabihf-root ./build.sh skipmscorlib arm cross verbose ${lowerConfiguration}"""
1725                                         
1726                                         // Basic archiving of the build, no pal tests
1727                                         Utilities.addArchival(newJob, "bin/Product/**")
1728                                         break
1729                                     }
1730                                     else {
1731                                         // Unmount previously mounted rootfs and mount the Linux ARM emulator rootfs at /opt/linux-arm-emulator-root/
1732                                         buildCommands += "if grep -qs '/opt/linux-arm-emulator-root' /proc/mounts; then sudo umount /opt/linux-arm-emulator-root; fi ; sudo mount /opt/linux-arm-emulator/platform/rootfs-t30.ext4 /opt/linux-arm-emulator-root/"
1733                                         // Remove old copy of coreclr and copy the latest version of coreclr
1734                                         // This need to be done as it is not possible to clone the repository inside the chroot jail
1735                                         buildCommands += "sudo rm -rf /opt/linux-arm-emulator-root/home/coreclr; sudo mkdir /opt/linux-arm-emulator-root/home/coreclr; sudo cp -R ./ /opt/linux-arm-emulator-root/home/coreclr"
1736
1737                                         // Chroot into the Linux ARM emulator environment and execute the build
1738                                         buildCommands += """echo \"Chrooting into Linux ARM emulator environment\"
1739                                                             sudo chroot /opt/linux-arm-emulator-root/ /bin/bash -x <<EOF
1740                                                             source /dotnet/setenv/setenv_coreclr.sh
1741                                                             cd home/coreclr
1742                                                             ./build.sh arm clean verbose skipmscorlib
1743 EOF"""
1744
1745                                         // Basic archiving of the build, no pal tests
1746                                         Utilities.addArchival(newJob, "/opt/linux-arm-emulator-root/home/coreclr/bin/Product/**")
1747                                         break
1748                                     }
1749                                 default:
1750                                     println("Unknown architecture: ${architecture}");
1751                                     assert false
1752                                     break
1753                             }
1754                             break
1755                         default:
1756                             println("Unknown os: ${os}");
1757                             assert false
1758                             break
1759                     }
1760                 
1761                     newJob.with {
1762                         steps {
1763                             if (os == 'Windows_NT') {
1764                                 buildCommands.each { buildCommand ->
1765                                     batchFile(buildCommand)
1766                                 }
1767                             }
1768                             else {
1769                                 buildCommands.each { buildCommand ->
1770                                     shell(buildCommand)
1771                                 }
1772                             }
1773                         }
1774                     }
1775                 } // os
1776             } // configuration
1777         } // architecture
1778     } // isPR
1779 } // scenario
1780
1781 // Create the Linux/OSX/CentOS coreclr test leg for debug and release and each scenario
1782 combinedScenarios.each { scenario ->
1783     [true, false].each { isPR ->
1784         // Architectures.  x64 only at this point
1785         ['x64'].each { architecture ->
1786             // Put the OS's supported for coreclr cross testing here
1787             Constants.crossList.each { os ->
1788                 Constants.configurationList.each { configuration ->
1789
1790                     if (Constants.jitStressModeScenarios.containsKey(scenario)) {
1791                         if (configuration != 'Checked') {
1792                             return
1793                         }
1794                         if (isCorefxTesting(scenario)) {
1795                             return
1796                         }
1797                         //Skip stress modes for these scenarios
1798                         if (os == 'RHEL7.2' || os == 'Debian8.4' || os == 'OpenSUSE13.2') {
1799                             return
1800                         }
1801                     }
1802                     // If this is a r2r jitstress, jitstressregs, jitminopts or forcerelocs scenario
1803                     // and configuration is not Checked, bail out.
1804                     else if (configuration != 'Checked' && Constants.r2rJitStressScenarios.indexOf(scenario) != -1) {
1805                         return;
1806                     }
1807                     // For CentOS, we only want Checked/Release pri1 builds.
1808                     else if (os == 'CentOS7.1') {
1809                         if (scenario != 'pri1' &&
1810                             scenario != 'r2r' && 
1811                             scenario != 'pri1r2r' && 
1812                             scenario != 'gcstress15_pri1r2r' &&
1813                             Constants.r2rJitStressScenarios.indexOf(scenario) == -1) {
1814                             return
1815                         }
1816                         if (configuration != 'Checked' && configuration != 'Release') {
1817                             return
1818                         }
1819                     }
1820                     // For RedHat, Debian, and OpenSUSE, we only do Release pri1 builds.
1821                     else if (os == 'RHEL7.2' || os == 'Debian8.4' || os == 'OpenSUSE13.2') {
1822                         if (scenario != 'pri1') {
1823                             return
1824                         }
1825                         if (configuration != 'Release') {
1826                             return
1827                         }
1828                     }
1829                     else {
1830                         // Skip scenarios
1831                         switch (scenario) {
1832                             case 'pri1':
1833                                 // Nothing skipped
1834                                 break
1835                             case 'ilrt':
1836                                 break
1837                             case 'r2r':
1838                                 //Skip configs that aren't Checked or Release (so just Debug, for now)
1839                                 if (configuration != 'Checked' && configuration != 'Release') {
1840                                     return
1841                                 }
1842                                 break
1843                             case 'pri1r2r':
1844                                 //Skip configs that aren't Checked or Release (so just Debug, for now)
1845                                 if (configuration != 'Checked' && configuration != 'Release') {
1846                                     return
1847                                 }
1848                                 break
1849                             case 'gcstress15_pri1r2r':
1850                             case 'r2r_jitstress1':
1851                             case 'r2r_jitstress2':
1852                             case 'r2r_jitstressregs1':
1853                             case 'r2r_jitstressregs2':
1854                             case 'r2r_jitstressregs3':
1855                             case 'r2r_jitstressregs4':
1856                             case 'r2r_jitstressregs8':
1857                             case 'r2r_jitstressregsx10':
1858                             case 'r2r_jitstressregsx80':
1859                             case 'r2r_jitminopts':
1860                             case 'r2r_jitforcerelocs':
1861                                 //Skip configs that aren't Checked or Release (so just Debug, for now)
1862                                 if (configuration != 'Checked' && configuration != 'Release') {
1863                                     return
1864                                 }
1865                                 break
1866                             case 'longgc':
1867                             case 'gcsimulator':
1868                                 // Long GC tests take a long time on non-Release builds
1869                                 if (configuration != 'Release') {
1870                                     return
1871                                 }
1872                                 break
1873                             case 'coverage':
1874                                 //We only want Ubuntu Release for coverage
1875                                 if (os != 'Ubuntu') {
1876                                     return
1877                                 }
1878                                 if (configuration != 'Release') {
1879                                     return
1880                                 }
1881                             case 'default':
1882                                 // Nothing skipped
1883                                 break
1884                             default:
1885                                 println("Unknown scenario: ${scenario}")
1886                                 assert false
1887                                 break
1888                         }
1889                     }
1890                     
1891                     def lowerConfiguration = configuration.toLowerCase()
1892                     def osGroup = getOSGroup(os)
1893                     def jobName = getJobName(configuration, architecture, os, scenario, false) + "_tst"
1894                     // Unless this is a coverage test run, we want to copy over the default build of coreclr.
1895                     def inputScenario = 'default'
1896                     if (scenario == 'coverage') {
1897                         inputScenario = 'coverage'
1898                     }
1899                     def inputCoreCLRBuildName = projectFolder + '/' + 
1900                         Utilities.getFullJobName(project, getJobName(configuration, architecture, os, inputScenario, false), isPR)
1901                     // If this is a stress scenario, there isn't any difference in the build job
1902                     // so we didn't create a build only job for windows_nt specific to that stress mode.  Just copy
1903                     // from the default scenario
1904                     def testBuildScenario = scenario
1905                     if (testBuildScenario == 'coverage' || testBuildScenario == 'pri1r2r'|| testBuildScenario == 'gcstress15_pri1r2r') {
1906                         testBuildScenario = 'pri1'
1907                     }
1908                     else if ( testBuildScenario == 'r2r' || isLongGc(testBuildScenario)) {
1909                         testBuildScenario = 'default'
1910                     }
1911                     def inputWindowTestsBuildName = ''
1912                     if (Constants.jitStressModeScenarios.containsKey(testBuildScenario)) {
1913                         inputWindowTestsBuildName = projectFolder + '/' + 
1914                             Utilities.getFullJobName(project, getJobName(configuration, architecture, 'windows_nt', 'default', true), isPR)
1915                     }
1916                     else {
1917                         inputWindowTestsBuildName = projectFolder + '/' + 
1918                             Utilities.getFullJobName(project, getJobName(configuration, architecture, 'windows_nt', testBuildScenario, true), isPR)
1919                     }
1920                     // Enable Server GC for Ubuntu PR builds
1921                     def serverGCString = ''
1922                     
1923                     // Whether or not this test run should be run sequentially instead
1924                     // of in parallel. Only used for long GC tests.
1925                     def sequentialString = ''
1926                     
1927                     // Whether or not this test run should run a specific playlist.
1928                     // Only used for long GC tests.
1929
1930                     // A note - runtest.sh does have "--long-gc" and "--gcsimulator" options
1931                     // for running long GC and GCSimulator tests, respectively. We don't use them
1932                     // here because using a playlist file produces much more readable output on the CI machines
1933                     // and reduces running time.
1934                     def playlistString = ''
1935                      
1936                     if (os == 'Ubuntu' && isPR){
1937                         serverGCString = '--useServerGC'
1938                     }
1939
1940                     // pass --crossgen to runtest.sh for crossgen builds
1941                     def crossgenStr = ''
1942                     def runcrossgentestsStr = ''
1943                     def runjitstressStr = ''
1944                     def runjitstressregsStr = ''
1945                     def runjitmioptsStr = ''
1946                     def runjitforcerelocsStr = ''
1947                     def gcstressStr = ''
1948
1949                     if (scenario == 'r2r' ||
1950                         scenario == 'pri1r2r' ||
1951                         scenario == 'gcstress15_pri1r2r' ||
1952                         Constants.r2rJitStressScenarios.indexOf(scenario) != -1) {
1953                             crossgenStr = '--crossgen'
1954                             runcrossgentestsStr = '--runcrossgentests'
1955                                             
1956                             if (scenario == 'r2r_jitstress1'){
1957                                 runjitstressStr = '--jitstress=1'
1958                             }
1959                             else if (scenario == 'r2r_jitstress2') {
1960                                 runjitstressStr = '--jitstress=2'
1961                             }
1962                             else if (scenario == 'r2r_jitstressregs1'){
1963                                 runjitstressregsStr = '--jitstressregs=1'
1964                             }
1965                             else if (scenario == 'r2r_jitstressregs2') {
1966                                 runjitstressregsStr = '--jitstressregs=2'
1967                             }
1968                             else if (scenario == 'r2r_jitstressregs3') {
1969                                 runjitstressregsStr = '--jitstressregs=3'
1970                             }
1971                             else if (scenario == 'r2r_jitstressregs4') {
1972                                 runjitstressregsStr = '--jitstressregs=4'
1973                             }
1974                             else if (scenario == 'r2r_jitstressregs8') {
1975                                 runjitstressregsStr = '--jitstressregs=8'
1976                             }
1977                             else if (scenario == 'r2r_jitstressregsx10') {
1978                                 runjitstressregsStr = '--jitstressregs=x10'
1979                             }
1980                             else if (scenario == 'r2r_jitstressregsx80') {
1981                                 runjitstressregsStr = '--jitstressregs=x80'
1982                             }
1983                             else if (scenario == 'r2r_jitminopts') {
1984                                 runjitmioptsStr = '--jitminopts'
1985                             }
1986                             else if (scenario == 'r2r_jitforcerelocs') {
1987                                 runjitforcerelocsStr = '--jitforcerelocs'
1988                             }
1989                     }
1990                     if  (scenario == 'gcstress15_pri1r2r')
1991                     {
1992                         gcstressStr = '--gcstresslevel=0xF'
1993                     }
1994
1995                     if (isLongGc(scenario)) {
1996                         // Long GC tests behave very poorly when they are not
1997                         // the only test running (many of them allocate until OOM).
1998                         sequentialString = '--sequential'
1999                         
2000                         // The Long GC playlist contains all of the tests that are
2001                         // going to be run. The GCSimulator playlist contains all of
2002                         // the GC simulator tests.
2003                         if (scenario == 'longgc') {
2004                             playlistString = '--long-gc --playlist=./tests/longRunningGcTests.txt'
2005                         }
2006                         else if (scenario == 'gcsimulator') {
2007                             playlistString = '--gcsimulator --playlist=./tests/gcSimulatorTests.txt'
2008                         }
2009                     }
2010                     
2011
2012                     def newJob = job(Utilities.getFullJobName(project, jobName, isPR)) {
2013                         // Add parameters for the inputs
2014                     
2015                         parameters {
2016                             stringParam('CORECLR_WINDOWS_BUILD', '', 'Build number to copy CoreCLR windows test binaries from')
2017                             stringParam('CORECLR_BUILD', '', "Build number to copy CoreCLR ${osGroup} binaries from")
2018                         }
2019                     
2020                         steps {
2021                             // Set up the copies
2022                             
2023                             // Coreclr build we are trying to test
2024                             
2025                             copyArtifacts(inputCoreCLRBuildName) {
2026                                 excludePatterns('**/testResults.xml', '**/*.ni.dll')
2027                                 buildSelector {
2028                                     buildNumber('${CORECLR_BUILD}')
2029                                 }
2030                             }
2031                         
2032                             // Coreclr build containing the tests and mscorlib
2033                         
2034                             copyArtifacts(inputWindowTestsBuildName) {
2035                                 excludePatterns('**/testResults.xml', '**/*.ni.dll')
2036                                 buildSelector {
2037                                     buildNumber('${CORECLR_WINDOWS_BUILD}')
2038                                 }
2039                             }
2040
2041                             if (scenario == 'coverage') {
2042                                 // Move coreclr to clr directory
2043                                 shell("rm -rf .clr; mkdir .clr; mv * .clr; mv .git .clr; mv .clr clr")
2044                                 
2045                                 // Unzip the tests first.  Exit with 0
2046                                 shell("unzip -q -o ./clr/bin/tests/tests.zip -d ./clr/bin/tests/Windows_NT.${architecture}.${configuration} || exit 0")
2047
2048                                 shell("ls clr/bin")
2049                                 // Get corefx
2050                                 shell("git clone https://github.com/dotnet/corefx fx")
2051                                 shell("ls")
2052                                 shell("pwd")
2053                                 // Build Linux corefx
2054                                 shell("./fx/build.sh x64 release Linux skiptests")
2055                                 // Check contents of bin directory - this can be removed after we confirm everything is as expected
2056                                 shell("ls ./fx/bin")
2057
2058                                 // Run corefx tests
2059                                 shell("""./fx/run-test.sh \\
2060                 --coreclr-bins \$(pwd)/clr/bin/Product/${osGroup}.${architecture}.${configuration} \\
2061                 --mscorlib-bins \$(pwd)/clr/bin/Product/${osGroup}.${architecture}.${configuration} \\
2062                 --corefx-tests \$(pwd)/fx/bin/tests/${osGroup}.AnyCPU.${configuration} \\
2063                 --corefx-native-bins \$(pwd)/fx/bin/${osGroup}.${architecture}.${configuration} \\
2064                 --configurationGroup Release""")
2065
2066
2067                                 // Run coreclr tests w/ workstation GC
2068                                 shell("""./clr/tests/runtest.sh \\
2069                 --testRootDir=\"\$(pwd)/clr/bin/tests/Windows_NT.${architecture}.${configuration}\" \\
2070                 --testNativeBinDir=\"\$(pwd)/clr/bin/obj/${osGroup}.${architecture}.${configuration}/tests\" \\
2071                 --coreClrBinDir=\"\$(pwd)/clr/bin/Product/${osGroup}.${architecture}.${configuration}\" \\
2072                 --mscorlibDir=\"\$(pwd)/clr/bin/Product/${osGroup}.${architecture}.${configuration}\" \\
2073                 --coreFxBinDir=\"\$(pwd)/fx/bin/${osGroup}.AnyCPU.Release;\$(pwd)/fx/bin/Unix.AnyCPU.Release;\$(pwd)/fx/bin/AnyOS.AnyCPU.Release\" \\
2074                 --coreFxNativeBinDir=\"\$(pwd)/fx/bin/${osGroup}.${architecture}.Release\" \\
2075                 --crossgen""")
2076
2077                                 // Run coreclr GC tests w/ server GC enabled & produce coverage reports
2078                                 shell("""./clr/tests/runtest.sh \\
2079                 --testRootDir=\"\$(pwd)/clr/bin/tests/Windows_NT.${architecture}.${configuration}/GC\" \\
2080                 --testNativeBinDir=\"\$(pwd)/clr/bin/obj/${osGroup}.${architecture}.${configuration}/tests\" \\
2081                 --coreOverlayDir=\"\$(pwd)/clr/bin/tests/Windows_NT.${architecture}.${configuration}/Tests/coreoverlay\" \\
2082                 --crossgen --useServerGC --coreclr-coverage \\
2083                 --coreclr-objs=\"\$(pwd)/clr/bin/obj/${osGroup}.${architecture}.${configuration}\" \\
2084                 --coreclr-src=\"\$(pwd)/clr/src\" \\
2085                 --coverage-output-dir=\"\${WORKSPACE}/coverage\" """)
2086
2087                             }
2088                             else {
2089
2090                                 def corefxFolder = Utilities.getFolderName('dotnet/corefx') + '/' + Utilities.getFolderName(branch)
2091                         
2092                                 // Corefx components.  We now have full stack builds on all distros we test here, so we can copy straight from CoreFX jobs.
2093                                 def osJobName = (os == 'Ubuntu') ? 'ubuntu14.04' : os.toLowerCase()
2094                                 copyArtifacts("${corefxFolder}/${osJobName}_release") {
2095                                     includePatterns('bin/build.tar.gz')
2096                                     buildSelector {
2097                                         latestSuccessful(true)
2098                                     }
2099                                 }
2100                         
2101                                 // Unpack the corefx binaries
2102                                 shell("tar -xf ./bin/build.tar.gz")
2103
2104                                 // Unzip the tests first.  Exit with 0
2105                                 shell("unzip -q -o ./bin/tests/tests.zip -d ./bin/tests/Windows_NT.${architecture}.${configuration} || exit 0")
2106                             
2107                                 // Execute the tests
2108                                 // If we are running a stress mode, we'll set those variables first
2109                                 def testEnvOpt = ""
2110                                 if (Constants.jitStressModeScenarios.containsKey(scenario)) {
2111                                     def scriptFileName = "\$WORKSPACE/set_stress_test_env.sh"
2112                                     def createScriptCmds = genStressModeScriptStep(os, scenario, Constants.jitStressModeScenarios[scenario], scriptFileName)
2113                                     if (createScriptCmds != "") {
2114                                         shell("${createScriptCmds}")
2115                                         testEnvOpt = "--test-env=" + scriptFileName
2116                                     }
2117                                 }
2118                                 
2119                                 if (isGCStressRelatedTesting(scenario)) {
2120                                     shell('./init-tools.sh')
2121                                 }
2122
2123                                 shell("""./tests/runtest.sh \\
2124                 --testRootDir=\"\${WORKSPACE}/bin/tests/Windows_NT.${architecture}.${configuration}\" \\
2125                 --testNativeBinDir=\"\${WORKSPACE}/bin/obj/${osGroup}.${architecture}.${configuration}/tests\" \\
2126                 --coreClrBinDir=\"\${WORKSPACE}/bin/Product/${osGroup}.${architecture}.${configuration}\" \\
2127                 --mscorlibDir=\"\${WORKSPACE}/bin/Product/${osGroup}.${architecture}.${configuration}\" \\
2128                 --coreFxBinDir=\"\${WORKSPACE}/bin/${osGroup}.AnyCPU.Release;\${WORKSPACE}/bin/Unix.AnyCPU.Release;\${WORKSPACE}/bin/AnyOS.AnyCPU.Release\" \\
2129                 --coreFxNativeBinDir=\"\${WORKSPACE}/bin/${osGroup}.${architecture}.Release\" \\
2130                 ${testEnvOpt} ${serverGCString} ${gcstressStr} ${crossgenStr} ${runcrossgentestsStr} ${runjitstressStr} ${runjitstressregsStr} ${runjitmioptsStr} ${runjitforcerelocsStr} ${sequentialString} ${playlistString}""")
2131                             }
2132                         }
2133                     }
2134
2135                     if (scenario == 'coverage') {
2136                         // Publish coverage reports
2137                         Utilities.addHtmlPublisher(newJob, '${WORKSPACE}/coverage', 'Code Coverage Report', 'coreclr.html')
2138                         addEmailPublisher(newJob, 'clrcoverage@microsoft.com')
2139                     }
2140
2141                     setMachineAffinity(newJob, os, architecture)
2142                     Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
2143                     // Set timeouts to 240.
2144                     setTestJobTimeOut(newJob, scenario)
2145                     Utilities.addXUnitDotNETResults(newJob, '**/coreclrtests.xml')
2146                 
2147                     // Create a build flow to join together the build and tests required to run this
2148                     // test.
2149                     // Windows CoreCLR build and Linux CoreCLR build (in parallel) ->
2150                     // Linux CoreCLR test
2151                     def flowJobName = getJobName(configuration, architecture, os, scenario, false) + "_flow"
2152                     def fullTestJobName = projectFolder + '/' + newJob.name
2153                     // Add a reference to the input jobs for report purposes
2154                     JobReport.Report.addReference(inputCoreCLRBuildName)
2155                     JobReport.Report.addReference(inputWindowTestsBuildName)
2156                     JobReport.Report.addReference(fullTestJobName)
2157                     def newFlowJob = buildFlowJob(Utilities.getFullJobName(project, flowJobName, isPR)) {
2158                         buildFlow("""
2159 // Build the input jobs in parallel
2160 parallel (
2161     { coreclrBuildJob = build(params, '${inputCoreCLRBuildName}') },
2162     { windowsBuildJob = build(params, '${inputWindowTestsBuildName}') }
2163 )
2164     
2165 // And then build the test build
2166 build(params + [CORECLR_BUILD: coreclrBuildJob.build.number, 
2167                 CORECLR_WINDOWS_BUILD: windowsBuildJob.build.number], '${fullTestJobName}')    
2168 """)
2169                     }
2170
2171                     setMachineAffinity(newFlowJob, os, architecture)
2172                     Utilities.standardJobSetup(newFlowJob, project, isPR, "*/${branch}")
2173                     addTriggers(newFlowJob, branch, isPR, architecture, os, configuration, scenario, true, false, false)
2174                 } // configuration
2175             } // os
2176         } // architecture
2177     } // isPR
2178 } // scenario
2179
2180 JobReport.Report.generateJobReport(out)