jenkins_master.groovy 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * BepInEx Bleeding Edge build CI jenkinsfile
  3. */
  4. pipeline {
  5. agent any
  6. parameters {
  7. // Check if the build is Bleeding Edge. Affects whether the result is pushed to BepisBuilds
  8. booleanParam(name: "IS_BE")
  9. }
  10. stages {
  11. stage('Pull Projects') {
  12. steps {
  13. // Clean up old project before starting
  14. cleanWs()
  15. dir('BepInEx') {
  16. git 'https://github.com/BepInEx/BepInEx.git'
  17. script {
  18. shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
  19. longCommit = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
  20. branchName = sh(returnStdout: true, script: "git rev-parse --abbrev-ref HEAD").trim()
  21. latestTag = sh(returnStdout: true, script: "git describe --tags `git rev-list --tags --max-count=1`").trim()
  22. if(!params.IS_BE) {
  23. latestTagOnCurrentBranch = sh(returnStdout: true, script: "git describe --abbrev=0 --tags").trim()
  24. sh("git checkout ${latestTagOnCurrentBranch}")
  25. }
  26. if(params.IS_BE)
  27. changelog = gitChangelog from: [type: 'REF', value: "${latestTag}"], returnType: 'STRING', template: """BepInEx Bleeding Edge Changelog
  28. Changes since ${latestTag}:
  29. {{#commits}}
  30. {{^merge}}
  31. * [{{hash}}] ({{authorName}}) {{messageTitle}}
  32. {{/merge}}
  33. {{/commits}}""", to: [type: 'COMMIT', value: "${longCommit}"]
  34. }
  35. sh 'git submodule update --init --recursive'
  36. }
  37. dir('Unity') {
  38. git credentialsId: 'b1f2f78b-f0c5-4a81-8b4a-55b6b8bdbbe3', url: 'http://localhost:6000/JenkinsStuff/UnityDLL.git'
  39. }
  40. dir('Doorstop') {
  41. sh ''' tag="v2.9.1.0";
  42. version="2.9.1.0";
  43. wget https://github.com/NeighTools/UnityDoorstop/releases/download/$tag/Doorstop_x64_$version.zip;
  44. wget https://github.com/NeighTools/UnityDoorstop/releases/download/$tag/Doorstop_x86_$version.zip;
  45. unzip -o Doorstop_x86_$version.zip version.dll -d x86;
  46. unzip -o Doorstop_x64_$version.zip version.dll -d x64;'''
  47. }
  48. }
  49. }
  50. stage('Prepare BepInEx') {
  51. steps {
  52. dir('BepInEx') {
  53. sh "mkdir -p lib"
  54. // Ghetto fix to force TargetFrameworks to only net35
  55. sh "find . -type f -name \"*.csproj\" -exec sed -i -E \"s/(<TargetFrameworks>)[^<]+(<\\/TargetFrameworks>)/\\1net35\\2/g\" {} +"
  56. sh "nuget restore"
  57. }
  58. dir('BepInEx/BepInEx') {
  59. // Write additional BuildInfo into the Bleeding Edge BepInEx.dll
  60. dir('Properties') {
  61. script {
  62. if(params.IS_BE) {
  63. sh "sed -i -E \"s/([0-9]+\\.[0-9]+\\.[0-9]+\\.)[0-9]+/\\1${env.BUILD_NUMBER}/\" AssemblyInfo.cs"
  64. sh "echo '[assembly: BuildInfo(\"BLEEDING EDGE Build #${env.BUILD_NUMBER} from ${shortCommit} at ${branchName}\")]' >> AssemblyInfo.cs"
  65. }
  66. versionNumber = sh(returnStdout: true, script: "grep -m 1 -oE \"[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\" AssemblyInfo.cs").trim()
  67. }
  68. }
  69. }
  70. }
  71. }
  72. stage('Build Legacy BepInEx') {
  73. steps {
  74. sh 'cp -f Unity/5.6/UnityEngine.dll BepInEx/lib/UnityEngine.dll'
  75. dir('BepInEx') {
  76. sh 'msbuild /p:Configuration=Legacy /t:Build /p:DebugType=none BepInEx.sln'
  77. }
  78. dir('Build/Legacy/bin') {
  79. sh 'cp -fr ../../../BepInEx/bin/* .'
  80. }
  81. dir('BepInEx/bin') {
  82. deleteDir()
  83. }
  84. }
  85. }
  86. stage('Build 2018 BepInEx') {
  87. steps {
  88. // sh 'cp -f Unity/2018/UnityEngine.CoreModule.dll BepInEx/lib/UnityEngine.CoreModule.dll'
  89. // TODO: Switch to 2018 version of UnityEngine.dll?
  90. sh 'cp -f Unity/5.6/UnityEngine.dll BepInEx/lib/UnityEngine.dll'
  91. dir('BepInEx') {
  92. sh 'msbuild /p:Configuration=v2018 /t:Build /p:DebugType=none BepInEx.sln'
  93. }
  94. dir('Build/v2018/bin') {
  95. sh 'cp -fr ../../../BepInEx/bin/* .'
  96. }
  97. dir('BepInEx/bin') {
  98. deleteDir()
  99. }
  100. }
  101. }
  102. stage('Package Legacy') {
  103. steps {
  104. dir('Build/Legacy/dist') {
  105. sh 'mkdir -p BepInEx/core BepInEx/patchers BepInEx/plugins'
  106. sh 'cp -fr -t BepInEx/core ../bin/*'
  107. sh 'rm -f BepInEx/core/UnityEngine.dll'
  108. sh 'rm -rf BepInEx/core/patcher'
  109. sh 'cp -f ../../../BepInEx/doorstop/doorstop_config.ini doorstop_config.ini'
  110. sh 'cp -f ../../../Doorstop/x86/version.dll version.dll'
  111. script {
  112. if(params.IS_BE) {
  113. writeFile encoding: 'UTF-8', file: 'changelog.txt', text: changelog
  114. sh 'unix2dos changelog.txt'
  115. commitPrefix = "_${shortCommit}_"
  116. }
  117. else
  118. commitPrefix = "_"
  119. }
  120. sh "zip -r9 BepInEx_Legacy_x86${commitPrefix}${versionNumber}.zip ./*"
  121. sh 'cp -f ../../../Doorstop/x64/version.dll version.dll'
  122. sh 'unix2dos doorstop_config.ini'
  123. sh "zip -r9 BepInEx_Legacy_x64${commitPrefix}${versionNumber}.zip ./* -x \\*.zip"
  124. archiveArtifacts "*.zip"
  125. }
  126. dir('Build/Legacy/patcher') {
  127. sh 'cp -fr ../bin/patcher/* .'
  128. script {
  129. if(params.IS_BE) {
  130. writeFile encoding: 'UTF-8', file: 'changelog.txt', text: changelog
  131. sh 'unix2dos changelog.txt'
  132. }
  133. }
  134. sh "zip -r9 BepInEx_Legacy_Patcher${commitPrefix}${versionNumber}.zip ./*"
  135. archiveArtifacts "*.zip"
  136. }
  137. }
  138. }
  139. stage('Package v2018') {
  140. steps {
  141. dir('Build/v2018/dist') {
  142. sh 'mkdir -p BepInEx/core BepInEx/patchers BepInEx/plugins'
  143. sh 'cp -fr -t BepInEx/core ../bin/*'
  144. sh 'rm -rf BepInEx/core/patcher'
  145. sh 'rm -f BepInEx/core/UnityEngine.dll'
  146. sh 'rm -f BepInEx/core/UnityEngine.CoreModule.dll'
  147. sh 'cp -f ../../../BepInEx/doorstop/doorstop_config.ini doorstop_config.ini'
  148. sh 'cp -f ../../../Doorstop/x86/version.dll version.dll'
  149. script {
  150. if(params.IS_BE) {
  151. writeFile encoding: 'UTF-8', file: 'changelog.txt', text: changelog
  152. sh 'unix2dos changelog.txt'
  153. commitPrefix = "_${shortCommit}_"
  154. }
  155. else
  156. commitPrefix = "_"
  157. }
  158. sh "zip -r9 BepInEx_v2018_x86${commitPrefix}${versionNumber}.zip ./*"
  159. sh 'cp -f ../../../Doorstop/x64/version.dll version.dll'
  160. sh 'unix2dos doorstop_config.ini'
  161. sh "zip -r9 BepInEx_v2018_x64${commitPrefix}${versionNumber}.zip ./* -x \\*.zip"
  162. archiveArtifacts "*.zip"
  163. }
  164. dir('Build/v2018/patcher') {
  165. sh 'cp -fr ../bin/patcher/* .'
  166. script {
  167. if(params.IS_BE) {
  168. writeFile encoding: 'UTF-8', file: 'changelog.txt', text: changelog
  169. sh 'unix2dos changelog.txt'
  170. }
  171. }
  172. sh "zip -r9 BepInEx_v2018_Patcher${commitPrefix}${versionNumber}.zip ./*"
  173. archiveArtifacts "*.zip"
  174. }
  175. }
  176. }
  177. }
  178. post {
  179. success {
  180. script {
  181. if(params.IS_BE) {
  182. // Write built BepInEx into bepisbuilds
  183. dir('Build/Legacy/dist') {
  184. sh "cp BepInEx_Legacy_x86_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  185. sh "cp BepInEx_Legacy_x64_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  186. }
  187. dir('Build/Legacy/patcher') {
  188. sh "cp BepInEx_Legacy_Patcher_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  189. }
  190. dir('Build/v2018/dist') {
  191. sh "cp BepInEx_v2018_x86_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  192. sh "cp BepInEx_v2018_x64_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  193. }
  194. dir('Build/v2018/patcher') {
  195. sh "cp BepInEx_v2018_Patcher_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  196. }
  197. sh "echo \"`date -Iseconds -u`;${env.BUILD_NUMBER};${shortCommit};BepInEx_Legacy_x86_${shortCommit}_${versionNumber}.zip;BepInEx_Legacy_x64_${shortCommit}_${versionNumber}.zip;BepInEx_v2018_x86_${shortCommit}_${versionNumber}.zip;BepInEx_v2018_x64_${shortCommit}_${versionNumber}.zip;BepInEx_Legacy_Patcher_${shortCommit}_${versionNumber}.zip;BepInEx_v2018_Patcher_${shortCommit}_${versionNumber}.zip\" >> /var/www/bepisbuilds/builds/bepinex_be/artifacts_list"
  198. }
  199. }
  200. //Notify Bepin Discord of successfull build
  201. withCredentials([string(credentialsId: 'discord-notify-webhook', variable: 'DISCORD_WEBHOOK')]) {
  202. discordSend description: "**Build:** [${currentBuild.id}](${env.BUILD_URL})\n**Status:** [${currentBuild.currentResult}](${env.BUILD_URL})\n\n[**Artifacts on BepisBuilds**](http://builds.bepis.io/bepinex_be)", footer: 'Jenkins via Discord Notifier', link: env.BUILD_URL, successful: currentBuild.resultIsBetterOrEqualTo('SUCCESS'), title: "${env.JOB_NAME} #${currentBuild.id}", webhookURL: DISCORD_WEBHOOK
  203. }
  204. }
  205. failure {
  206. //Notify Discord of failed build
  207. withCredentials([string(credentialsId: 'discord-notify-webhook', variable: 'DISCORD_WEBHOOK')]) {
  208. discordSend description: "**Build:** [${currentBuild.id}](${env.BUILD_URL})\n**Status:** [${currentBuild.currentResult}](${env.BUILD_URL})", footer: 'Jenkins via Discord Notifier', link: env.BUILD_URL, successful: currentBuild.resultIsBetterOrEqualTo('SUCCESS'), title: "${env.JOB_NAME} #${currentBuild.id}", webhookURL: DISCORD_WEBHOOK
  209. }
  210. }
  211. }
  212. }