netci.groovy 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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_NT': 'Windows', // Windows Server 2012 R2, equivalent to Windows 8.1 (aka Blue)
  18. 'Ubuntu16.04': 'Ubuntu',
  19. 'OSX10.12': 'OSX'
  20. ]
  21. def dailyRegex = 'dailies'
  22. // ---------------
  23. // HELPER CLOSURES
  24. // ---------------
  25. def CreateBuildTask = { isPR, buildArch, buildType, machine, configTag, buildExtra, testExtra, runCodeAnalysis, excludeConfigIf, nonDefaultTaskSetup ->
  26. if (excludeConfigIf && excludeConfigIf(isPR, buildArch, buildType)) {
  27. return // early exit: we don't want to create a job for this configuration
  28. }
  29. def config = "${buildArch}_${buildType}"
  30. config = (configTag == null) ? config : "${configTag}_${config}"
  31. // params: Project, BaseTaskName, IsPullRequest (appends '_prtest')
  32. def jobName = Utilities.getFullJobName(project, config, isPR)
  33. def testableConfig = buildType in ['debug', 'test'] && buildArch != 'arm'
  34. def analysisConfig = buildType in ['release'] && runCodeAnalysis
  35. def buildScript = "call .\\jenkins\\buildone.cmd ${buildArch} ${buildType} "
  36. buildScript += buildExtra ?: ''
  37. buildScript += analysisConfig ? ' "/p:runcodeanalysis=true"' : ''
  38. def testScript = "call .\\jenkins\\testone.cmd ${buildArch} ${buildType} "
  39. testScript += testExtra ?: ''
  40. def analysisScript = '.\\Build\\scripts\\check_prefast_error.ps1 . CodeAnalysis.err'
  41. def newJob = job(jobName) {
  42. // This opens the set of build steps that will be run.
  43. // This looks strange, but it is actually a method call, with a
  44. // closure as a param, since Groovy allows method calls without parens.
  45. // (Compare with '.each' method used above.)
  46. steps {
  47. batchFile(buildScript) // run the parameter as if it were a batch file
  48. if (testableConfig) {
  49. batchFile(testScript)
  50. }
  51. if (analysisConfig) {
  52. powerShell(analysisScript)
  53. }
  54. }
  55. }
  56. def msbuildType = msbuildTypeMap.get(buildType)
  57. def msbuildFlavor = "build_${buildArch}${msbuildType}"
  58. def archivalString = "test/${msbuildFlavor}.*,test/logs/**"
  59. archivalString += analysisConfig ? ',CodeAnalysis.err' : ''
  60. Utilities.addArchival(newJob, archivalString,
  61. '', // no exclusions from archival
  62. false, // doNotFailIfNothingArchived=false ~= failIfNothingArchived
  63. false) // archiveOnlyIfSuccessful=false ~= archiveAlways
  64. Utilities.setMachineAffinity(newJob, machine, 'latest-or-auto')
  65. Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
  66. if (nonDefaultTaskSetup == null) {
  67. if (isPR) {
  68. def osTag = machineTypeToOSTagMap.get(machine)
  69. Utilities.addGithubPRTriggerForBranch(newJob, branch, "${osTag} ${config}")
  70. } else {
  71. Utilities.addGithubPushTrigger(newJob)
  72. }
  73. } else {
  74. // nonDefaultTaskSetup is e.g. DailyBuildTaskSetup (which sets up daily builds)
  75. // These jobs will only be configured for the branch specified below,
  76. // which is the name of the branch netci.groovy was processed for.
  77. // See list of such branches at:
  78. // https://github.com/dotnet/dotnet-ci/blob/master/jobs/data/repolist.txt
  79. nonDefaultTaskSetup(newJob, isPR, config)
  80. }
  81. }
  82. def CreateBuildTasks = { machine, configTag, buildExtra, testExtra, runCodeAnalysis, excludeConfigIf, nonDefaultTaskSetup ->
  83. [true, false].each { isPR ->
  84. ['x86', 'x64', 'arm'].each { buildArch ->
  85. ['debug', 'test', 'release'].each { buildType ->
  86. CreateBuildTask(isPR, buildArch, buildType, machine, configTag, buildExtra, testExtra, runCodeAnalysis, excludeConfigIf, nonDefaultTaskSetup)
  87. }
  88. }
  89. }
  90. }
  91. def CreateXPlatBuildTask = { isPR, buildType, staticBuild, machine, platform, configTag,
  92. xplatBranch, nonDefaultTaskSetup, customOption, testVariant, extraBuildParams ->
  93. def config = (platform == "osx" ? "osx_${buildType}" : "linux_${buildType}")
  94. def numConcurrentCommand = (platform == "osx" ? "sysctl -n hw.logicalcpu" : "nproc")
  95. config = (configTag == null) ? config : "${configTag}_${config}"
  96. config = staticBuild ? "static_${config}" : "shared_${config}"
  97. config = customOption ? customOption.replaceAll(/[-]+/, "_") + "_" + config : config
  98. // params: Project, BaseTaskName, IsPullRequest (appends '_prtest')
  99. def jobName = Utilities.getFullJobName(project, config, isPR)
  100. def infoScript = "bash jenkins/get_system_info.sh --${platform}"
  101. def buildFlag = buildType == "release" ? "" : (buildType == "debug" ? "--debug" : "--test-build")
  102. def staticFlag = staticBuild ? "--static" : ""
  103. def swbCheckFlag = (platform == "linux" && buildType == "debug" && !staticBuild) ? "--wb-check" : "";
  104. def icuFlag = (platform == "osx" ? "--icu=/usr/local/opt/icu4c/include" : "")
  105. def compilerPaths = (platform == "osx") ? "" : "--cxx=/usr/bin/clang++-3.9 --cc=/usr/bin/clang-3.9"
  106. def buildScript = "bash ./build.sh ${staticFlag} -j=`${numConcurrentCommand}` ${buildFlag} " +
  107. "${swbCheckFlag} ${compilerPaths} ${icuFlag} ${customOption} ${extraBuildParams}"
  108. def testScript = "bash test/runtests.sh \"${testVariant}\""
  109. def newJob = job(jobName) {
  110. steps {
  111. shell(infoScript)
  112. shell(buildScript)
  113. shell(testScript)
  114. }
  115. }
  116. def archivalString = "out/build.log"
  117. Utilities.addArchival(newJob, archivalString,
  118. '', // no exclusions from archival
  119. true, // doNotFailIfNothingArchived=false ~= failIfNothingArchived (true ~= doNotFail)
  120. false) // archiveOnlyIfSuccessful=false ~= archiveAlways
  121. Utilities.setMachineAffinity(newJob, machine, 'latest-or-auto')
  122. Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
  123. if (nonDefaultTaskSetup == null) {
  124. if (isPR) {
  125. def osTag = machineTypeToOSTagMap.get(machine)
  126. Utilities.addGithubPRTriggerForBranch(newJob, xplatBranch, "${osTag} ${config}")
  127. } else {
  128. Utilities.addGithubPushTrigger(newJob)
  129. }
  130. } else {
  131. // nonDefaultTaskSetup is e.g. DailyBuildTaskSetup (which sets up daily builds)
  132. // These jobs will only be configured for the branch specified below,
  133. // which is the name of the branch netci.groovy was processed for.
  134. // See list of such branches at:
  135. // https://github.com/dotnet/dotnet-ci/blob/master/jobs/data/repolist.txt
  136. nonDefaultTaskSetup(newJob, isPR, config)
  137. }
  138. }
  139. // Generic task to trigger clang-based cross-plat build tasks
  140. def CreateXPlatBuildTasks = { machine, platform, configTag, xplatBranch, nonDefaultTaskSetup, extraBuildParams ->
  141. [true, false].each { isPR ->
  142. CreateXPlatBuildTask(isPR, "test", "", machine, platform,
  143. configTag, xplatBranch, nonDefaultTaskSetup, "--no-jit", "--variants disable_jit", extraBuildParams)
  144. ['debug', 'test', 'release'].each { buildType ->
  145. def staticBuildConfigs = [true, false]
  146. if (platform == "osx") {
  147. staticBuildConfigs = [true]
  148. }
  149. staticBuildConfigs.each { staticBuild ->
  150. CreateXPlatBuildTask(isPR, buildType, staticBuild, machine, platform,
  151. configTag, xplatBranch, nonDefaultTaskSetup, "", "", extraBuildParams)
  152. }
  153. }
  154. }
  155. }
  156. def DailyBuildTaskSetup = { newJob, isPR, triggerName, groupRegex ->
  157. // The addition of triggers makes the job non-default in GitHub.
  158. if (isPR) {
  159. def triggerRegex = "(${dailyRegex}|${groupRegex}|${triggerName})"
  160. Utilities.addGithubPRTriggerForBranch(newJob, branch,
  161. triggerName, // GitHub task name
  162. "(?i).*test\\W+${triggerRegex}.*")
  163. } else {
  164. Utilities.addPeriodicTrigger(newJob, '@daily')
  165. }
  166. }
  167. def CreateStyleCheckTasks = { taskString, taskName, checkName ->
  168. [true, false].each { isPR ->
  169. def jobName = Utilities.getFullJobName(project, taskName, isPR)
  170. def newJob = job(jobName) {
  171. steps {
  172. shell(taskString)
  173. }
  174. }
  175. Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
  176. if (isPR) {
  177. // Set PR trigger.
  178. Utilities.addGithubPRTriggerForBranch(newJob, branch, checkName)
  179. } else {
  180. // Set a push trigger
  181. Utilities.addGithubPushTrigger(newJob)
  182. }
  183. Utilities.setMachineAffinity(newJob, 'Ubuntu16.04', 'latest-or-auto')
  184. }
  185. }
  186. // ----------------
  187. // INNER LOOP TASKS
  188. // ----------------
  189. CreateBuildTasks('Windows_NT', null, null, "-winBlue", true, null, null)
  190. // Add some additional daily configs to trigger per-PR as a quality gate:
  191. // x64_debug Slow Tests
  192. CreateBuildTask(true, 'x64', 'debug',
  193. 'Windows_NT', 'ci_slow', null, '-winBlue -includeSlow', false, null, null)
  194. // x64_debug DisableJIT
  195. CreateBuildTask(true, 'x64', 'debug',
  196. 'Windows_NT', 'ci_disablejit', '"/p:BuildJIT=false"', '-winBlue -disablejit', false, null, null)
  197. // x64_debug Lite
  198. CreateBuildTask(true, 'x64', 'debug',
  199. 'Windows_NT', 'ci_lite', '"/p:BuildLite=true"', '-winBlue -lite', false, null, null)
  200. // -----------------
  201. // DAILY BUILD TASKS
  202. // -----------------
  203. if (!branch.endsWith('-ci')) {
  204. // build and test on the usual configuration (VS 2015) with -includeSlow
  205. CreateBuildTasks('Windows_NT', 'daily_slow', null, '-winBlue -includeSlow', false,
  206. /* excludeConfigIf */ null,
  207. /* nonDefaultTaskSetup */ { newJob, isPR, config ->
  208. DailyBuildTaskSetup(newJob, isPR,
  209. "Windows ${config}",
  210. 'slow\\s+tests')})
  211. // build and test on the usual configuration (VS 2015) with JIT disabled
  212. CreateBuildTasks('Windows_NT', 'daily_disablejit', '"/p:BuildJIT=false"', '-winBlue -disablejit', true,
  213. /* excludeConfigIf */ null,
  214. /* nonDefaultTaskSetup */ { newJob, isPR, config ->
  215. DailyBuildTaskSetup(newJob, isPR,
  216. "Windows ${config}",
  217. '(disablejit|nojit)\\s+tests')})
  218. }
  219. // ----------------
  220. // CODE STYLE TASKS
  221. // ----------------
  222. CreateStyleCheckTasks('./jenkins/check_copyright.sh', 'ubuntu_check_copyright', 'Copyright Check')
  223. CreateStyleCheckTasks('./jenkins/check_eol.sh', 'ubuntu_check_eol', 'EOL Check')
  224. CreateStyleCheckTasks('./jenkins/check_tabs.sh', 'ubuntu_check_tabs', 'Tab Check')
  225. // --------------
  226. // XPLAT BRANCHES
  227. // --------------
  228. // Explicitly enumerate xplat-incompatible branches, because we don't anticipate any future incompatible branches
  229. def isXPlatCompatibleBranch = !(branch in ['release/1.1', 'release/1.1-ci', 'release/1.2', 'release/1.2-ci'])
  230. // Include these explicitly-named branches
  231. def isXPlatDailyBranch = branch in ['master', 'linux', 'xplat']
  232. // Include some release/* branches (ignore branches ending in '-ci')
  233. if (branch.startsWith('release') && !branch.endsWith('-ci')) {
  234. // Allows all current and future release/* branches on which we should run daily builds of XPlat configs.
  235. // RegEx matches branch names we should ignore (e.g. release/1.1, release/1.2, release/1.2-pre)
  236. includeReleaseBranch = !(branch =~ /^release\/(1\.[12](\D.*)?)$/)
  237. isXPlatDailyBranch |= includeReleaseBranch
  238. }
  239. // -----------------
  240. // LINUX BUILD TASKS
  241. // -----------------
  242. if (isXPlatCompatibleBranch) {
  243. def osString = 'Ubuntu16.04'
  244. // PR and CI checks
  245. CreateXPlatBuildTasks(osString, "linux", "ubuntu", branch, null, "")
  246. // Create a PR/continuous task to check ubuntu/static/debug/no-icu
  247. [true, false].each { isPR ->
  248. CreateXPlatBuildTask(isPR, "debug", true, osString, "linux",
  249. "ubuntu", branch, null, "--no-icu", "--not-tag exclude_noicu", "")
  250. }
  251. // daily builds
  252. if (isXPlatDailyBranch) {
  253. CreateXPlatBuildTasks(osString, "linux", "daily_ubuntu", branch,
  254. /* nonDefaultTaskSetup */ { newJob, isPR, config ->
  255. DailyBuildTaskSetup(newJob, isPR,
  256. "Ubuntu ${config}",
  257. 'linux\\s+tests')},
  258. /* extraBuildParams */ "--extra-defines=PERFMAP_TRACE_ENABLED=1")
  259. }
  260. }
  261. // ---------------
  262. // OSX BUILD TASKS
  263. // ---------------
  264. if (isXPlatCompatibleBranch) {
  265. def osString = 'OSX10.12'
  266. // PR and CI checks
  267. CreateXPlatBuildTasks(osString, "osx", "osx", branch, null, "")
  268. // daily builds
  269. if (isXPlatDailyBranch) {
  270. CreateXPlatBuildTasks(osString, "osx", "daily_osx", branch,
  271. /* nonDefaultTaskSetup */ { newJob, isPR, config ->
  272. DailyBuildTaskSetup(newJob, isPR,
  273. "OSX ${config}",
  274. 'linux\\s+tests')},
  275. /* extraBuildParams */ "")
  276. }
  277. }
  278. // ------------
  279. // HELP MESSAGE
  280. // ------------
  281. Utilities.createHelperJob(this, project, branch,
  282. "Welcome to the ${project} Repository", // This is prepended to the help message
  283. "For additional documentation on ChakraCore CI checks, please see:\n" +
  284. "\n" +
  285. "* https://github.com/Microsoft/ChakraCore/wiki/Jenkins-CI-Checks\n" +
  286. "* https://github.com/Microsoft/ChakraCore/wiki/Jenkins-Build-Triggers\n" +
  287. "* https://github.com/Microsoft/ChakraCore/wiki/Jenkins-Repro-Steps\n" +
  288. "\n" +
  289. "Have a nice day!") // This is appended to the help message. You might put known issues here.