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