Advertisement
Guest User

jenkins code

a guest
Jun 20th, 2022
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.50 KB | None | 0 0
  1. #!/usr/bin/env groovy
  2.  
  3. package hudson.scm
  4. import groovy.io.FileType
  5.  
  6. def RunEditorStages = false
  7. def RunCompileStages = false
  8. def RunCookStages = false
  9. def MergeToStable = false
  10. def RunPackageRelease = false
  11. def RunDeploy = false
  12. def UploadToS3 = false
  13.  
  14. def BuildPlatforms = [
  15. [
  16. Name: "Android Client",
  17. BuildGraphClientTarget: "Compile Client Android",
  18. BuildGraphCookTarget: "Cook Android",
  19. Package: ""
  20. ],
  21. [
  22. Name: "Windows Client",
  23. BuildGraphClientTarget: "Compile Client Win64",
  24. BuildGraphCookTarget: "Cook WindowsNoEditor",
  25. Package: ""
  26. ]
  27.  
  28. ]
  29.  
  30. def WindowsServerPlatform = [
  31. Name: "Windows Server",
  32. BuildGraphClientTarget: "Compile Server Win64",
  33. BuildGraphCookTarget: "Cook WindowsServer",
  34. Package: ""
  35. ]
  36.  
  37. def LinuxServerPlatform = [
  38. Name: "Linux Server",
  39. BuildGraphClientTarget: "Compile Server Linux",
  40. BuildGraphCookTarget: "Cook LinuxServer",
  41. Package: ""
  42. ]
  43.  
  44. def Workspace = "E:\\Jenkins\\workspace\\MyProject-Programming (CI)"
  45.  
  46. pipeline
  47. {
  48. agent
  49. {
  50. node
  51. {
  52. label 'windows'
  53. }
  54. }
  55.  
  56. parameters
  57. {
  58. booleanParam(name: 'ForceEditor', defaultValue: false, description: 'Force this job to compile editor whether there were code changes or not')
  59.  
  60. booleanParam(name: 'ForceCompile', defaultValue: false, description: 'Force this job to compile whether there were code changes or not')
  61.  
  62. booleanParam(name: 'ForceCook', defaultValue: false, description: 'Force this job to cook whether there were asset changes or not')
  63.  
  64. booleanParam(name: 'ForceDeploy', defaultValue: false, description: 'Force this job to remove old servers and deploy the new server')
  65. booleanParam(name: 'ForcePackage', defaultValue: false, description: 'Force this job to package and release the clients for all platforms')
  66.  
  67. booleanParam(name: 'ForceS3Upload', defaultValue: false, description: 'Force this job to upload the build files to S3')
  68.  
  69. string(name: 'GameConfiguration', defaultValue: "Development", description: 'Development or Shipping')
  70. booleanParam(name: 'LinuxServer', defaultValue: false, description: 'True if the platform of the server build should be Linux, otherwise false')
  71. }
  72.  
  73. environment
  74. {
  75. ProjectName = "DS_Template"
  76. ProjectDepotPath = "//MyProject/main"
  77. ProjectGamePath = "/${ProjectName}"
  78. ProjectEditorBinariesDepotPath = "//MyProject/binaries"
  79. ProjectWorkSpace = "jenkins-${JOB_NAME}"
  80. UATPath = "Engine\\Build\\BatchFiles\\RunUAT.bat"
  81. PostBadgeStatusPath = "Engine\\Build\\BatchFiles\\PostBadgeStatus.bat"
  82. UGSRestUrl = "http://bumblebee:8081"
  83.  
  84. BuildEditorBuildGraphScript = "Engine/Build/Graph/Examples/BuildEditorAndTools.xml"
  85. BuildGameBuildGraphScript = "${ProjectName}/Build/Graph/PackageGame.xml"
  86. CookGameBuildGraphScript = "${ProjectName}/Build/Graph/PackageGame.xml"
  87.  
  88. AppBatchFilesPath = "${ProjectName}\\Build\\BatchFiles"
  89. LocalDeployDirectory = "${ProjectName}\\Deploy"
  90. LocalArchiveDirectory = "${ProjectName}\\Deploy\\Archives"
  91.  
  92. uebp_PORT = "${env.P4_PORT}"
  93. uebp_CLIENT = "${env.P4_CLIENT}"
  94. uebp_USER = "${env.P4_USER}"
  95. }
  96.  
  97. stages
  98. {
  99. stage ('Check Change List')
  100. {
  101. steps
  102. {
  103. script
  104. {
  105. String[] SourceFileTypes = [".cpp", ".h", ".hpp", ".cs", ".jenkins-ci", ".bat", ".uproject", ".uplugin"]
  106. String[] ContentFileTypes = [".uasset", ".umap", ".ini", ".jenkins-ci"]
  107. if (params.ForceEditor)
  108. {
  109. RunEditorStages = true
  110. }
  111. else
  112. {
  113. RunEditorStages = searchChangeListForFileTypes(SourceFileTypes)
  114. }
  115.  
  116. if (params.ForceCompile)
  117. {
  118. RunCompileStages = true
  119. }
  120. else
  121. {
  122. RunCompileStages = searchChangeListForFileTypes(SourceFileTypes)
  123. }
  124.  
  125. if (params.ForceCook)
  126. {
  127. RunCookStages = true
  128. }
  129. else
  130. {
  131. RunCookStages = searchChangeListForFileTypes(ContentFileTypes)
  132. }
  133. if (params.ForceDeploy)
  134. {
  135. RunDeploy = true
  136. }
  137. else
  138. {
  139. RunDeploy = searchChangeListForFileTypes(ContentFileTypes) || searchChangeListForFileTypes(SourceFileTypes)
  140. }
  141.  
  142. if (params.ForcePackage)
  143. {
  144. RunPackageRelease = true
  145. }
  146. else
  147. {
  148. RunPackageRelease = searchChangeListForFileTypes(ContentFileTypes) || searchChangeListForFileTypes(SourceFileTypes)
  149. }
  150.  
  151. if (params.ForceS3Upload)
  152. {
  153. UploadToS3 = true
  154. }
  155. else
  156. {
  157. // TODO: think about this more
  158. UploadToS3 = ForcePackage || ForceDeploy
  159. }
  160.  
  161. if (!RunEditorStages)
  162. {
  163. bat """%PostBadgeStatusPath% -Name=Editor -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Success -Url=%BUILD_URL%"""
  164. }
  165. }
  166. }
  167. }
  168.  
  169. stage('Compile Editor')
  170. {
  171. when
  172. {
  173. expression { RunEditorStages == true }
  174. }
  175. steps
  176. {
  177. bat """%PostBadgeStatusPath% -Name=Editor -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Starting -Url=%BUILD_URL%"""
  178. bat """%UATPath% BuildGraph -Script=%BuildEditorBuildGraphScript% -Target="Submit To Perforce for UGS" -set:EditorTarget=%ProjectName%Editor -set:ArchiveStream=%ProjectEditorBinariesDepotPath% -p4 -submit -verbose -BuildMachine"""
  179. }
  180. post
  181. {
  182. success
  183. {
  184. bat """%PostBadgeStatusPath% -Name=Editor -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Success -Url=%BUILD_URL%"""
  185. }
  186. failure
  187. {
  188. bat """%PostBadgeStatusPath% -Name=Editor -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Failure -Url=%BUILD_URL%"""
  189. }
  190. }
  191. }
  192.  
  193. stage('Compile Game')
  194. {
  195. when
  196. {
  197. expression { RunCompileStages == true }
  198. }
  199. steps
  200. {
  201. bat """%PostBadgeStatusPath% -Name=Game -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Starting -Url=%BUILD_URL%"""
  202. script
  203. {
  204. if (params.LinuxServer)
  205. {
  206. BuildPlatforms << LinuxServerPlatform
  207. }
  208. else
  209. {
  210. BuildPlatforms << WindowsServerPlatform
  211. }
  212. for (Platform in BuildPlatforms)
  213. {
  214. stage(Platform.Name)
  215. {
  216. bat """%UATPath% BuildGraph -Script=%BuildGameBuildGraphScript% -Target="${Platform.BuildGraphClientTarget}" -set:GameConfiguration=${params.GameConfiguration} -BuildMachine"""
  217. }
  218. }
  219. }
  220. }
  221. post
  222. {
  223. success
  224. {
  225. bat """%PostBadgeStatusPath% -Name=Game -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Success -Url=%BUILD_URL%"""
  226. }
  227. failure
  228. {
  229. bat """%PostBadgeStatusPath% -Name=Game -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Failure -Url=%BUILD_URL%"""
  230. }
  231. }
  232. }
  233.  
  234. stage('Cook Game')
  235. {
  236. when
  237. {
  238. expression { RunCookStages == true }
  239. }
  240. steps
  241. {
  242. bat """%PostBadgeStatusPath% -Name=Cook -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Starting -Url=%BUILD_URL%"""
  243. script
  244. {
  245. for (Platform in BuildPlatforms)
  246. {
  247. stage(Platform.Name)
  248. {
  249. bat """%UATPath% BuildGraph -Script=%CookGameBuildGraphScript% -Target="${Platform.BuildGraphCookTarget}" -BuildMachine"""
  250.  
  251. def logLines = currentBuild.rawBuild.getLog(200)
  252. for (int i = 0; i < logLines.size(); i++)
  253. {
  254. def logLine = logLines[i]
  255. if (logLine.contains("Array Inner Type mismatch") || logLine.contains("Can't find file"))
  256. {
  257. currentBuild.result = 'UNSTABLE'
  258. break;
  259. }
  260. }
  261. }
  262. }
  263. }
  264. }
  265. post
  266. {
  267. success
  268. {
  269. bat """%PostBadgeStatusPath% -Name=Cook -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Success -Url=%BUILD_URL%"""
  270. }
  271. failure
  272. {
  273. bat """%PostBadgeStatusPath% -Name=Cook -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Failure -Url=%BUILD_URL%"""
  274. }
  275. unstable
  276. {
  277. bat """%PostBadgeStatusPath% -Name=Cook -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Warning -Url=%BUILD_URL%"""
  278. }
  279. }
  280. }
  281.  
  282. stage('Deploy Server')
  283. {
  284. when
  285. {
  286. expression { RunDeploy == true }
  287. }
  288. steps
  289. {
  290. bat """%PostBadgeStatusPath% -Name=Deploy -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Starting -Url=%BUILD_URL%"""
  291. script
  292. {
  293. bat """%UATPath% BuildGraph -Script=%BuildGameBuildGraphScript% -Target="CleanUp PlayFabServers" -BuildMachine"""
  294.  
  295. if (params.LinuxServer)
  296. {
  297. // bat """%UATPath% BuildGraph -Script=%BuildGameBuildGraphScript% -Target="Stage LinuxServer" -set:GameConfiguration=${params.GameConfiguration} -set:ArchiveDirectory=%LocalDeployDirectory% -BuildMachine"""
  298. bat """%UATPath% BuildGraph -Script=%BuildGameBuildGraphScript% -Target="Deploy LinuxServer" -set:GameConfiguration=${params.GameConfiguration} -set:ArchiveDirectory=%LocalDeployDirectory% -BuildMachine"""
  299. }
  300. else
  301. {
  302. // bat """%UATPath% BuildGraph -Script=%BuildGameBuildGraphScript% -Target="Stage WindowsServer" -set:GameConfiguration=${params.GameConfiguration} -set:ArchiveDirectory=%LocalDeployDirectory% -BuildMachine"""
  303. bat """%UATPath% BuildGraph -Script=%BuildGameBuildGraphScript% -Target="Deploy WindowsServer" -set:GameConfiguration=${params.GameConfiguration} -set:ArchiveDirectory=%LocalDeployDirectory% -BuildMachine"""
  304. }
  305. }
  306. }
  307. post
  308. {
  309. success
  310. {
  311. bat """%PostBadgeStatusPath% -Name=Deploy -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Success -Url=%BUILD_URL%"""
  312. }
  313. failure
  314. {
  315. bat """%PostBadgeStatusPath% -Name=Deploy -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Failure -Url=%BUILD_URL%"""
  316. }
  317. unstable
  318. {
  319. bat """%PostBadgeStatusPath% -Name=Deploy -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Warning -Url=%BUILD_URL%"""
  320. }
  321. }
  322. }
  323.  
  324. stage('Package Game')
  325. {
  326. when
  327. {
  328. expression { RunPackageRelease == true }
  329. }
  330. steps
  331. {
  332. script
  333. {
  334. bat """%PostBadgeStatusPath% -Name=Release -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Starting -Url=%BUILD_URL%"""
  335. bat """%UATPath% BuildGraph -Script=%BuildGameBuildGraphScript% -Target="Stage Android" -set:GameConfiguration=${params.GameConfiguration} -set:ArchiveDirectory=%LocalDeployDirectory% -BuildMachine"""
  336. bat """%UATPath% BuildGraph -Script=%BuildGameBuildGraphScript% -Target="Stage WindowsNoEditor" -set:GameConfiguration=${params.GameConfiguration} -set:ArchiveDirectory=%LocalDeployDirectory% -BuildMachine"""
  337. bat """%UATPath% BuildGraph -Script=%BuildGameBuildGraphScript% -Target="Generate CL and Archive Builds" -set:GameConfiguration=${params.GameConfiguration} -set:ChangeList=%P4_CHANGELIST% -set:P4Root=%ProjectDepotPath% -BuildMachine"""
  338. }
  339. }
  340. post
  341. {
  342. success
  343. {
  344. bat """%PostBadgeStatusPath% -Name=Release -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Success -Url=%BUILD_URL%"""
  345. }
  346. failure
  347. {
  348. bat """%PostBadgeStatusPath% -Name=Release -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Failure -Url=%BUILD_URL%"""
  349. }
  350. unstable
  351. {
  352. bat """%PostBadgeStatusPath% -Name=Release -Change=%P4_CHANGELIST% -Project=%ProjectDepotPath%%ProjectGamePath% -RestUrl=%UGSRestUrl% -Status=Warning -Url=%BUILD_URL%"""
  353. }
  354. }
  355. }
  356. }
  357. }
  358.  
  359. @NonCPS
  360. def searchChangeListForFileTypes(String[] fileTypes)
  361. {
  362. //According to docs should be able to use a changeset expression in the when clause but that wouldn't work.
  363. def changeLogSets = currentBuild.rawBuild.getChangeSets()
  364. for (int i = 0; i < changeLogSets.size(); i++)
  365. {
  366. def entries = changeLogSets[i].items
  367. for (int j = 0; j < entries.length; j++)
  368. {
  369. def entry = entries[j]
  370. def files = new ArrayList(entry.affectedFiles)
  371. for (int k = 0; k < files.size(); k++)
  372. {
  373. def file = files[k].path
  374. echo "${file}"
  375. for (int l = 0; l < fileTypes.length; l++)
  376. {
  377. def fileType = fileTypes[l]
  378. echo "${fileType}"
  379. if (file.contains(fileType))
  380. {
  381. return true
  382. }
  383. }
  384. }
  385. }
  386. }
  387.  
  388. return false
  389. }
  390.  
  391. @NonCPS
  392. def searchChangeListForCommitComment(String tag)
  393. {
  394. //According to docs should be able to use a changeset expression in the when clause but that wouldn't work.
  395. def changeLogSets = currentBuild.rawBuild.getChangeSets()
  396. for (int i = 0; i < changeLogSets.size(); i++)
  397. {
  398. def entries = changeLogSets[i].items
  399. for (int j = 0; j < entries.length; j++)
  400. {
  401. def entry = entries[j]
  402. def message = entry.msg;
  403. if (message.contains(tag))
  404. {
  405. return true;
  406. }
  407. }
  408. }
  409.  
  410. return false
  411. }
  412.  
  413. @NonCPS
  414. def findReleaseVersion()
  415. {
  416. //According to docs should be able to use a changeset expression in the when clause but that wouldn't work.
  417. def changeLogSets = currentBuild.rawBuild.getChangeSets()
  418. for (int i = 0; i < changeLogSets.size(); i++)
  419. {
  420. def entries = changeLogSets[i].items
  421. for (int j = 0; j < entries.length; j++)
  422. {
  423. def entry = entries[j]
  424. def message = entry.msg;
  425. if (message.contains("#release"))
  426. {
  427. int releaseIndex = message.indexOf("#release")
  428. return message.substring(releaseIndex + 1, releaseIndex + 6)
  429. }
  430. }
  431. }
  432.  
  433. return ""
  434. }
  435.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement