netci.groovy 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 icuFlag = (platform == "osx" ? "--icu=/usr/local/opt/icu4c/include" : "")
  104. def compilerPaths = (platform == "osx") ? "" : "--cxx=/usr/bin/clang++-3.8 --cc=/usr/bin/clang-3.8"
  105. def buildScript = "bash ./build.sh ${staticFlag} -j=`${numConcurrentCommand}` ${buildFlag} ${compilerPaths} ${icuFlag} ${customOption}"
  106. def testScript = "bash test/runtests.sh \"${testVariant}\""
  107. def newJob = job(jobName) {
  108. steps {
  109. shell(infoScript)
  110. shell(buildScript)
  111. shell(testScript)
  112. }
  113. }
  114. def archivalString = "BuildLinux/build.log"
  115. Utilities.addArchival(newJob, archivalString,
  116. '', // no exclusions from archival
  117. true, // doNotFailIfNothingArchived=false ~= failIfNothingArchived (true ~= doNotFail)
  118. false) // archiveOnlyIfSuccessful=false ~= archiveAlways
  119. Utilities.setMachineAffinity(newJob, machine, 'latest-or-auto')
  120. Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
  121. if (nonDefaultTaskSetup == null) {
  122. if (isPR) {
  123. def osTag = machineTypeToOSTagMap.get(machine)
  124. Utilities.addGithubPRTriggerForBranch(newJob, xplatBranch, "${osTag} ${config}")
  125. } else {
  126. Utilities.addGithubPushTrigger(newJob)
  127. }
  128. } else {
  129. // nonDefaultTaskSetup is e.g. DailyBuildTaskSetup (which sets up daily builds)
  130. // These jobs will only be configured for the branch specified below,
  131. // which is the name of the branch netci.groovy was processed for.
  132. // See list of such branches at:
  133. // https://github.com/dotnet/dotnet-ci/blob/master/jobs/data/repolist.txt
  134. nonDefaultTaskSetup(newJob, isPR, config)
  135. }
  136. }
  137. // Generic task to trigger clang-based cross-plat build tasks
  138. def CreateXPlatBuildTasks = { machine, platform, configTag, xplatBranch, nonDefaultTaskSetup ->
  139. [true, false].each { isPR ->
  140. CreateXPlatBuildTask(isPR, "test", "", machine, platform,
  141. configTag, xplatBranch, nonDefaultTaskSetup, "--no-jit", "--variants disable_jit")
  142. ['debug', 'test', 'release'].each { buildType ->
  143. def staticBuildConfigs = [true, false]
  144. if (platform == "osx") {
  145. staticBuildConfigs = [true]
  146. }
  147. staticBuildConfigs.each { staticBuild ->
  148. CreateXPlatBuildTask(isPR, buildType, staticBuild, machine, platform,
  149. configTag, xplatBranch, nonDefaultTaskSetup, "", "")
  150. }
  151. }
  152. }
  153. }
  154. def DailyBuildTaskSetup = { newJob, isPR, triggerName, groupRegex ->
  155. // The addition of triggers makes the job non-default in GitHub.
  156. if (isPR) {
  157. def triggerRegex = "(${dailyRegex}|${groupRegex}|${triggerName})"
  158. Utilities.addGithubPRTriggerForBranch(newJob, branch,
  159. triggerName, // GitHub task name
  160. "(?i).*test\\W+${triggerRegex}.*")
  161. } else {
  162. Utilities.addPeriodicTrigger(newJob, '@daily')
  163. }
  164. }
  165. def CreateStyleCheckTasks = { taskString, taskName, checkName ->
  166. [true, false].each { isPR ->
  167. def jobName = Utilities.getFullJobName(project, taskName, isPR)
  168. def newJob = job(jobName) {
  169. steps {
  170. shell(taskString)
  171. }
  172. }
  173. Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
  174. if (isPR) {
  175. // Set PR trigger.
  176. Utilities.addGithubPRTriggerForBranch(newJob, branch, checkName)
  177. } else {
  178. // Set a push trigger
  179. Utilities.addGithubPushTrigger(newJob)
  180. }
  181. Utilities.setMachineAffinity(newJob, 'Ubuntu16.04', 'latest-or-auto')
  182. }
  183. }
  184. // ----------------
  185. // INNER LOOP TASKS
  186. // ----------------
  187. CreateBuildTasks('Windows_NT', null, null, null, true, null, null)
  188. // Add some additional daily configs to trigger per-PR as a quality gate:
  189. // x64_debug Slow Tests
  190. CreateBuildTask(true, 'x64', 'debug',
  191. 'Windows_NT', 'ci_slow', null, '-includeSlow', false, null, null)
  192. // x64_debug DisableJIT
  193. CreateBuildTask(true, 'x64', 'debug',
  194. 'Windows_NT', 'ci_disablejit', '"/p:BuildJIT=false"', '-disablejit', false, null, null)
  195. // x64_debug Legacy
  196. CreateBuildTask(true, 'x64', 'debug',
  197. 'Windows 7', 'ci_dev12', 'msbuild12', '-win7 -includeSlow', false, null, null)
  198. // -----------------
  199. // DAILY BUILD TASKS
  200. // -----------------
  201. if (!branch.endsWith('-ci')) {
  202. // build and test on Windows 7 with VS 2013 (Dev12/MsBuild12)
  203. CreateBuildTasks('Windows 7', 'daily_dev12', 'msbuild12', '-win7 -includeSlow', false,
  204. /* excludeConfigIf */ { isPR, buildArch, buildType -> (buildArch == 'arm') },
  205. /* nonDefaultTaskSetup */ { newJob, isPR, config ->
  206. DailyBuildTaskSetup(newJob, isPR,
  207. "Windows 7 ${config}",
  208. '(dev12|legacy)\\s+tests')})
  209. // build and test on the usual configuration (VS 2015) with -includeSlow
  210. CreateBuildTasks('Windows_NT', 'daily_slow', null, '-includeSlow', false,
  211. /* excludeConfigIf */ null,
  212. /* nonDefaultTaskSetup */ { newJob, isPR, config ->
  213. DailyBuildTaskSetup(newJob, isPR,
  214. "Windows ${config}",
  215. 'slow\\s+tests')})
  216. // build and test on the usual configuration (VS 2015) with JIT disabled
  217. CreateBuildTasks('Windows_NT', 'daily_disablejit', '"/p:BuildJIT=false"', '-disablejit', true,
  218. /* excludeConfigIf */ null,
  219. /* nonDefaultTaskSetup */ { newJob, isPR, config ->
  220. DailyBuildTaskSetup(newJob, isPR,
  221. "Windows ${config}",
  222. '(disablejit|nojit)\\s+tests')})
  223. }
  224. // ----------------
  225. // CODE STYLE TASKS
  226. // ----------------
  227. CreateStyleCheckTasks('./jenkins/check_copyright.sh', 'ubuntu_check_copyright', 'Copyright Check')
  228. CreateStyleCheckTasks('./jenkins/check_eol.sh', 'ubuntu_check_eol', 'EOL Check')
  229. CreateStyleCheckTasks('./jenkins/check_tabs.sh', 'ubuntu_check_tabs', 'Tab Check')
  230. // --------------
  231. // XPLAT BRANCHES
  232. // --------------
  233. // Explicitly enumerate xplat-incompatible branches, because we don't anticipate any future incompatible branches
  234. def isXPlatCompatibleBranch = !(branch in ['release/1.1', 'release/1.1-ci', 'release/1.2', 'release/1.2-ci'])
  235. // Include these explicitly-named branches
  236. def isXPlatDailyBranch = branch in ['master', 'linux', 'xplat']
  237. // Include some release/* branches (ignore branches ending in '-ci')
  238. if (branch.startsWith('release') && !branch.endsWith('-ci')) {
  239. // Allows all current and future release/* branches on which we should run daily builds of XPlat configs.
  240. // RegEx matches branch names we should ignore (e.g. release/1.1, release/1.2, release/1.2-pre)
  241. includeReleaseBranch = !(branch =~ /^release\/(1\.[12](\D.*)?)$/)
  242. isXPlatDailyBranch |= includeReleaseBranch
  243. }
  244. // -----------------
  245. // LINUX BUILD TASKS
  246. // -----------------
  247. if (isXPlatCompatibleBranch) {
  248. def osString = 'Ubuntu16.04'
  249. // PR and CI checks
  250. CreateXPlatBuildTasks(osString, "linux", "ubuntu", branch, null)
  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. }
  259. }
  260. // ---------------
  261. // OSX BUILD TASKS
  262. // ---------------
  263. if (isXPlatCompatibleBranch) {
  264. def osString = 'OSX'
  265. // PR and CI checks
  266. CreateXPlatBuildTasks(osString, "osx", "osx", branch, null)
  267. // daily builds
  268. if (isXPlatDailyBranch) {
  269. CreateXPlatBuildTasks(osString, "osx", "daily_osx", branch,
  270. /* nonDefaultTaskSetup */ { newJob, isPR, config ->
  271. DailyBuildTaskSetup(newJob, isPR,
  272. "OSX ${config}",
  273. 'linux\\s+tests')})
  274. }
  275. }
  276. // ------------
  277. // HELP MESSAGE
  278. // ------------
  279. Utilities.createHelperJob(this, project, branch,
  280. "Welcome to the ${project} Repository", // This is prepended to the help message
  281. "For additional documentation on ChakraCore CI checks, please see:\n" +
  282. "\n" +
  283. "* https://github.com/Microsoft/ChakraCore/wiki/Jenkins-CI-Checks\n" +
  284. "* https://github.com/Microsoft/ChakraCore/wiki/Jenkins-Build-Triggers\n" +
  285. "* https://github.com/Microsoft/ChakraCore/wiki/Jenkins-Repro-Steps\n" +
  286. "\n" +
  287. "Have a nice day!") // This is appended to the help message. You might put known issues here.