netci.groovy 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. // Import the utility functionality.
  6. import jobs.generation.Utilities;
  7. // Grab the github project name passed in
  8. def project = GithubProject
  9. def branch = GithubBranchName
  10. def msbuildTypeMap = [
  11. 'debug':'chk',
  12. 'test':'test',
  13. 'release':'fre'
  14. ]
  15. // convert `machine` parameter to OS component of PR task name
  16. def machineTypeToOSTagMap = [
  17. 'Windows 7': 'Windows 7',
  18. 'Windows_NT': 'Windows'
  19. ]
  20. def dailyRegex = 'dailies'
  21. // Only generate PR check triggers for the version of netci.groovy in the master branch
  22. // since those PR checks will apply for all branches.
  23. def jobTypesToGenerate = [false]
  24. if (branch == 'master') {
  25. // OK to generate PR checks (this ensures we only generate one set of them)
  26. jobTypesToGenerate += true
  27. }
  28. // ---------------
  29. // HELPER CLOSURES
  30. // ---------------
  31. def CreateBuildTasks = { machine, configTag, buildExtra, testExtra, runCodeAnalysis, excludeConfigIf, nonDefaultTaskSetup ->
  32. jobTypesToGenerate.each { isPR ->
  33. ['x86', 'x64', 'arm'].each { buildArch ->
  34. ['debug', 'test', 'release'].each { buildType ->
  35. if (excludeConfigIf && excludeConfigIf(isPR, buildArch, buildType)) {
  36. return // early exit: we don't want to create a job for this configuration
  37. }
  38. def config = "${buildArch}_${buildType}"
  39. config = (configTag == null) ? config : "${configTag}_${config}"
  40. // params: Project, BaseTaskName, IsPullRequest (appends '_prtest')
  41. def jobName = Utilities.getFullJobName(project, config, isPR)
  42. def testableConfig = buildType in ['debug', 'test'] && buildArch != 'arm'
  43. def analysisConfig = buildType in ['release'] && runCodeAnalysis
  44. def buildScript = "call .\\jenkins\\buildone.cmd ${buildArch} ${buildType} "
  45. buildScript += buildExtra ?: ''
  46. buildScript += analysisConfig ? ' "/p:runcodeanalysis=true"' : ''
  47. def testScript = "call .\\jenkins\\testone.cmd ${buildArch} ${buildType} "
  48. testScript += testExtra ?: ''
  49. def analysisScript = '.\\Build\\scripts\\check_prefast_error.ps1 . CodeAnalysis.err'
  50. def newJob = job(jobName) {
  51. // This opens the set of build steps that will be run.
  52. // This looks strange, but it is actually a method call, with a
  53. // closure as a param, since Groovy allows method calls without parens.
  54. // (Compare with '.each' method used above.)
  55. steps {
  56. batchFile(buildScript) // run the parameter as if it were a batch file
  57. if (testableConfig) {
  58. batchFile(testScript)
  59. }
  60. if (analysisConfig) {
  61. powerShell(analysisScript)
  62. }
  63. }
  64. }
  65. Utilities.setMachineAffinity(newJob, machine, 'latest-or-auto')
  66. def msbuildType = msbuildTypeMap.get(buildType)
  67. def msbuildFlavor = "build_${buildArch}${msbuildType}"
  68. def archivalString = "test/${msbuildFlavor}.*,test/logs/**"
  69. archivalString += analysisConfig ? ',CodeAnalysis.err' : ''
  70. Utilities.addArchival(newJob, archivalString,
  71. '', // no exclusions from archival
  72. false, // doNotFailIfNothingArchived=false ~= failIfNothingArchived
  73. false) // archiveOnlyIfSuccessful=false ~= archiveAlways
  74. Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
  75. if (nonDefaultTaskSetup == null) {
  76. if (isPR) {
  77. def osTag = machineTypeToOSTagMap.get(machine)
  78. // Set up checks which apply to PRs targeting any branch
  79. Utilities.addGithubPRTrigger(newJob, "${osTag} ${config}")
  80. // To enable PR checks only for specific target branches, use the following instead:
  81. // Utilities.addGithubPRTriggerForBranch(newJob, branch, checkName)
  82. } else {
  83. Utilities.addGithubPushTrigger(newJob)
  84. }
  85. } else {
  86. // nonDefaultTaskSetup is e.g. DailyBuildTaskSetup (which sets up daily builds)
  87. // These jobs will only be configured for the branch specified below,
  88. // which is the name of the branch netci.groovy was processed for.
  89. // See list of such branches at:
  90. // https://github.com/dotnet/dotnet-ci/blob/master/jobs/data/repolist.txt
  91. nonDefaultTaskSetup(newJob, isPR, config)
  92. }
  93. }
  94. }
  95. }
  96. }
  97. def DailyBuildTaskSetup = { newJob, isPR, triggerName, groupRegex ->
  98. // The addition of triggers makes the job non-default in GitHub.
  99. if (isPR) {
  100. def triggerRegex = "(${dailyRegex}|${groupRegex}|${triggerName})"
  101. Utilities.addGithubPRTrigger(newJob,
  102. triggerName, // GitHub task name
  103. "(?i).*test\\W+${triggerRegex}.*")
  104. } else {
  105. Utilities.addPeriodicTrigger(newJob, '@daily')
  106. }
  107. }
  108. def CreateStyleCheckTasks = { taskString, taskName, checkName ->
  109. [true, false].each { isPR ->
  110. def jobName = Utilities.getFullJobName(project, taskName, isPR)
  111. def newJob = job(jobName) {
  112. steps {
  113. shell(taskString)
  114. }
  115. }
  116. Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
  117. if (isPR) {
  118. // Set PR trigger.
  119. Utilities.addGithubPRTrigger(newJob, checkName)
  120. } else {
  121. // Set a push trigger
  122. Utilities.addGithubPushTrigger(newJob)
  123. }
  124. Utilities.setMachineAffinity(newJob, 'Ubuntu14.04', 'latest-or-auto')
  125. }
  126. }
  127. // ----------------
  128. // INNER LOOP TASKS
  129. // ----------------
  130. CreateBuildTasks('Windows_NT', null, null, null, true, null, null)
  131. // -----------------
  132. // DAILY BUILD TASKS
  133. // -----------------
  134. // build and test on Windows 7 with VS 2013 (Dev12/MsBuild12)
  135. CreateBuildTasks('Windows 7', 'daily_dev12', 'msbuild12', '-win7 -includeSlow', false,
  136. /* excludeConfigIf */ { isPR, buildArch, buildType -> (buildArch == 'arm') },
  137. /* nonDefaultTaskSetup */ { newJob, isPR, config ->
  138. DailyBuildTaskSetup(newJob, isPR,
  139. "Windows 7 ${config}",
  140. '(dev12|legacy)\\s+tests')})
  141. // build and test on the usual configuration (VS 2015) with -includeSlow
  142. CreateBuildTasks('Windows_NT', 'daily_slow', null, '-includeSlow', false,
  143. /* excludeConfigIf */ null,
  144. /* nonDefaultTaskSetup */ { newJob, isPR, config ->
  145. DailyBuildTaskSetup(newJob, isPR,
  146. "Windows ${config}",
  147. 'slow\\s+tests')})
  148. // build and test on the usual configuration (VS 2015) with JIT disabled
  149. CreateBuildTasks('Windows_NT', 'daily_disablejit', '"/p:BuildJIT=false"', '-disablejit', true,
  150. /* excludeConfigIf */ null,
  151. /* nonDefaultTaskSetup */ { newJob, isPR, config ->
  152. DailyBuildTaskSetup(newJob, isPR,
  153. "Windows ${config}",
  154. '(disablejit|nojit)\\s+tests')})
  155. // ----------------
  156. // CODE STYLE TASKS
  157. // ----------------
  158. CreateStyleCheckTasks('./jenkins/check_eol.sh', 'ubuntu_check_eol', 'EOL Check')
  159. CreateStyleCheckTasks('./jenkins/check_copyright.sh', 'ubuntu_check_copyright', 'Copyright Check')