jenkins_master.groovy 9.6 KB

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