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 7': 'Windows 7',
  18. 'Windows_NT': 'Windows',
  19. 'Ubuntu16.04': 'Ubuntu',
  20. 'OSX': 'OSX'
  21. ]
  22. def dailyRegex = 'dailies'
  23. // ---------------
  24. // HELPER CLOSURES
  25. // ---------------
  26. def CreateBuildTask = { isPR, buildArch, buildType, machine, configTag, buildExtra, testExtra, runCodeAnalysis, excludeConfigIf, nonDefaultTaskSetup ->
  27. if (excludeConfigIf && excludeConfigIf(isPR, buildArch, buildType)) {
  28. return // early exit: we don't want to create a job for this configuration
  29. }
  30. def config = "${buildArch}_${buildType}"
  31. config = (configTag == null) ? config : "${configTag}_${config}"
  32. // params: Project, BaseTaskName, IsPullRequest (appends '_prtest')
  33. def jobName = Utilities.getFullJobName(project, config, isPR)
  34. def testableConfig = buildType in ['debug', 'test'] && buildArch != 'arm'
  35. def analysisConfig = buildType in ['release'] && runCodeAnalysis
  36. def buildScript = "call .\\jenkins\\buildone.cmd ${buildArch} ${buildType} "
  37. buildScript += buildExtra ?: ''
  38. buildScript += analysisConfig ? ' "/p:runcodeanalysis=true"' : ''
  39. def testScript = "call .\\jenkins\\testone.cmd ${buildArch} ${buildType} "
  40. testScript += testExtra ?: ''
  41. def analysisScript = '.\\Build\\scripts\\check_prefast_error.ps1 . CodeAnalysis.err'
  42. def newJob = job(jobName) {
  43. // This opens the set of build steps that will be run.
  44. // This looks strange, but it is actually a method call, with a
  45. // closure as a param, since Groovy allows method calls without parens.
  46. // (Compare with '.each' method used above.)
  47. steps {
  48. batchFile(buildScript) // run the parameter as if it were a batch file
  49. if (testableConfig) {
  50. batchFile(testScript)
  51. }
  52. if (analysisConfig) {
  53. powerShell(analysisScript)
  54. }
  55. }
  56. }
  57. def msbuildType = msbuildTypeMap.get(buildType)
  58. def msbuildFlavor = "build_${buildArch}${msbuildType}"
  59. def archivalString = "test/${msbuildFlavor}.*,test/logs/**"
  60. archivalString += analysisConfig ? ',CodeAnalysis.err' : ''
  61. Utilities.addArchival(newJob, archivalString,
  62. '', // no exclusions from archival
  63. false, // doNotFailIfNothingArchived=false ~= failIfNothingArchived
  64. false) // archiveOnlyIfSuccessful=false ~= archiveAlways
  65. Utilities.setMachineAffinity(newJob, machine, 'latest-or-auto')
  66. Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
  67. if (nonDefaultTaskSetup == null) {
  68. if (isPR) {
  69. def osTag = machineTypeToOSTagMap.get(machine)
  70. Utilities.addGithubPRTriggerForBranch(newJob, branch, "${osTag} ${config}")
  71. } else {
  72. Utilities.addGithubPushTrigger(newJob)
  73. }
  74. } else {
  75. // nonDefaultTaskSetup is e.g. DailyBuildTaskSetup (which sets up daily builds)
  76. // These jobs will only be configured for the branch specified below,
  77. // which is the name of the branch netci.groovy was processed for.
  78. // See list of such branches at:
  79. // https://github.com/dotnet/dotnet-ci/blob/master/jobs/data/repolist.txt
  80. nonDefaultTaskSetup(newJob, isPR, config)
  81. }
  82. }
  83. def CreateBuildTasks = { machine, configTag, buildExtra, testExtra, runCodeAnalysis, excludeConfigIf, nonDefaultTaskSetup ->
  84. [true, false].each { isPR ->
  85. ['x86', 'x64', 'arm'].each { buildArch ->
  86. ['debug', 'test', 'release'].each { buildType ->
  87. CreateBuildTask(isPR, buildArch, buildType, machine, configTag, buildExtra, testExtra, runCodeAnalysis, excludeConfigIf, nonDefaultTaskSetup)
  88. }
  89. }
  90. }
  91. }
  92. def CreateXPlatBuildTask = { isPR, buildType, staticBuild, machine, platform, configTag,
  93. xplatBranch, nonDefaultTaskSetup, customOption, testVariant ->
  94. def config = (platform == "osx" ? "osx_${buildType}" : "linux_${buildType}")
  95. def numConcurrentCommand = (platform == "osx" ? "sysctl -n hw.logicalcpu" : "nproc")
  96. config = (configTag == null) ? config : "${configTag}_${config}"
  97. config = staticBuild ? "${config}_static" : config
  98. // params: Project, BaseTaskName, IsPullRequest (appends '_prtest')
  99. def jobName = Utilities.getFullJobName(project, config, isPR) + customOption.replaceAll(/[-]+/, "_")
  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.8 --cc=/usr/bin/clang-3.8"
  106. def buildScript = "bash ./build.sh ${staticFlag} -j=`${numConcurrentCommand}` ${buildFlag} " +
  107. "${swbCheckFlag} ${compilerPaths} ${icuFlag} ${customOption}"
  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 ->
  141. [true, false].each { isPR ->
  142. CreateXPlatBuildTask(isPR, "test", "", machine, platform,
  143. configTag, xplatBranch, nonDefaultTaskSetup, "--no-jit", "--variants disable_jit")
  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, "", "")
  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, null, 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, '-includeSlow', false, null, null)
  194. // x64_debug DisableJIT
  195. CreateBuildTask(true, 'x64', 'debug',
  196. 'Windows_NT', 'ci_disablejit', '"/p:BuildJIT=false"', '-disablejit', false, null, null)
  197. // x64_debug Legacy
  198. CreateBuildTask(true, 'x64', 'debug',
  199. 'Windows 7', 'ci_dev12', 'msbuild12', '-win7 -includeSlow', false, null, null)
  200. // -----------------
  201. // DAILY BUILD TASKS
  202. // -----------------
  203. if (!branch.endsWith('-ci')) {
  204. // build and test on Windows 7 with VS 2013 (Dev12/MsBuild12)
  205. CreateBuildTasks('Windows 7', 'daily_dev12', 'msbuild12', '-win7 -includeSlow', false,
  206. /* excludeConfigIf */ { isPR, buildArch, buildType -> (buildArch == 'arm') },
  207. /* nonDefaultTaskSetup */ { newJob, isPR, config ->
  208. DailyBuildTaskSetup(newJob, isPR,
  209. "Windows 7 ${config}",
  210. '(dev12|legacy)\\s+tests')})
  211. // build and test on the usual configuration (VS 2015) with -includeSlow
  212. CreateBuildTasks('Windows_NT', 'daily_slow', null, '-includeSlow', false,
  213. /* excludeConfigIf */ null,
  214. /* nonDefaultTaskSetup */ { newJob, isPR, config ->
  215. DailyBuildTaskSetup(newJob, isPR,
  216. "Windows ${config}",
  217. 'slow\\s+tests')})
  218. // build and test on the usual configuration (VS 2015) with JIT disabled
  219. CreateBuildTasks('Windows_NT', 'daily_disablejit', '"/p:BuildJIT=false"', '-disablejit', true,
  220. /* excludeConfigIf */ null,
  221. /* nonDefaultTaskSetup */ { newJob, isPR, config ->
  222. DailyBuildTaskSetup(newJob, isPR,
  223. "Windows ${config}",
  224. '(disablejit|nojit)\\s+tests')})
  225. }
  226. // ----------------
  227. // CODE STYLE TASKS
  228. // ----------------
  229. CreateStyleCheckTasks('./jenkins/check_copyright.sh', 'ubuntu_check_copyright', 'Copyright Check')
  230. CreateStyleCheckTasks('./jenkins/check_eol.sh', 'ubuntu_check_eol', 'EOL Check')
  231. CreateStyleCheckTasks('./jenkins/check_tabs.sh', 'ubuntu_check_tabs', 'Tab Check')
  232. // --------------
  233. // XPLAT BRANCHES
  234. // --------------
  235. // Explicitly enumerate xplat-incompatible branches, because we don't anticipate any future incompatible branches
  236. def isXPlatCompatibleBranch = !(branch in ['release/1.1', 'release/1.1-ci', 'release/1.2', 'release/1.2-ci'])
  237. // Include these explicitly-named branches
  238. def isXPlatDailyBranch = branch in ['master', 'linux', 'xplat']
  239. // Include some release/* branches (ignore branches ending in '-ci')
  240. if (branch.startsWith('release') && !branch.endsWith('-ci')) {
  241. // Allows all current and future release/* branches on which we should run daily builds of XPlat configs.
  242. // RegEx matches branch names we should ignore (e.g. release/1.1, release/1.2, release/1.2-pre)
  243. includeReleaseBranch = !(branch =~ /^release\/(1\.[12](\D.*)?)$/)
  244. isXPlatDailyBranch |= includeReleaseBranch
  245. }
  246. // -----------------
  247. // LINUX BUILD TASKS
  248. // -----------------
  249. if (isXPlatCompatibleBranch) {
  250. def osString = 'Ubuntu16.04'
  251. // PR and CI checks
  252. CreateXPlatBuildTasks(osString, "linux", "ubuntu", branch, null)
  253. // daily builds
  254. if (isXPlatDailyBranch) {
  255. CreateXPlatBuildTasks(osString, "linux", "daily_ubuntu", branch,
  256. /* nonDefaultTaskSetup */ { newJob, isPR, config ->
  257. DailyBuildTaskSetup(newJob, isPR,
  258. "Ubuntu ${config}",
  259. 'linux\\s+tests')})
  260. }
  261. }
  262. // ---------------
  263. // OSX BUILD TASKS
  264. // ---------------
  265. if (isXPlatCompatibleBranch) {
  266. def osString = 'OSX'
  267. // PR and CI checks
  268. CreateXPlatBuildTasks(osString, "osx", "osx", branch, null)
  269. // daily builds
  270. if (isXPlatDailyBranch) {
  271. CreateXPlatBuildTasks(osString, "osx", "daily_osx", branch,
  272. /* nonDefaultTaskSetup */ { newJob, isPR, config ->
  273. DailyBuildTaskSetup(newJob, isPR,
  274. "OSX ${config}",
  275. 'linux\\s+tests')})
  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.