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