jenkins_master.groovy 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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="$(curl -s https://api.github.com/repos/NeighTools/UnityDoorstop/releases/latest | grep "tag_name" | cut -d : -f 2 | tr -d "\\", ")";
  33. version="$(echo $tag | cut -c 2-)";
  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 'nuget restore'
  45. }
  46. dir('BepInEx/BepInEx') {
  47. // Write additional BuildInfo into the Bleeding Edge BepInEx.dll
  48. dir('Properties') {
  49. sh "echo '[assembly: BuildInfo(\"BLEEDING EDGE Build #${env.BUILD_NUMBER} from ${shortCommit} at ${branchName}\")]' >> AssemblyInfo.cs"
  50. sh "sed -i -E \"s/([0-9]+\\.[0-9]+\\.[0-9]+\\.)[0-9]+/\\1${env.BUILD_NUMBER}/\" AssemblyInfo.cs"
  51. script {
  52. versionNumber = sh(returnStdout: true, script: "grep -m 1 -oE \"[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\" AssemblyInfo.cs").trim()
  53. }
  54. }
  55. }
  56. }
  57. }
  58. stage('Build Legacy BepInEx') {
  59. steps {
  60. sh 'cp -f Unity/5.6/UnityEngine.dll BepInEx/lib/UnityEngine.dll'
  61. dir('BepInEx') {
  62. sh 'msbuild /p:Configuration=Legacy /t:Build /p:DebugType=none BepInEx.sln'
  63. }
  64. dir('Build/Legacy/bin') {
  65. sh 'cp -fr ../../../BepInEx/bin/* .'
  66. }
  67. dir('BepInEx/bin') {
  68. deleteDir()
  69. }
  70. }
  71. }
  72. stage('Build 2018 BepInEx') {
  73. steps {
  74. // sh 'cp -f Unity/2018/UnityEngine.CoreModule.dll BepInEx/lib/UnityEngine.CoreModule.dll'
  75. // TODO: Switch to 2018 version of UnityEngine.dll?
  76. sh 'cp -f Unity/5.6/UnityEngine.dll BepInEx/lib/UnityEngine.dll'
  77. dir('BepInEx') {
  78. sh 'msbuild /p:Configuration=v2018 /t:Build /p:DebugType=none BepInEx.sln'
  79. }
  80. dir('Build/v2018/bin') {
  81. sh 'cp -fr ../../../BepInEx/bin/* .'
  82. }
  83. dir('BepInEx/bin') {
  84. deleteDir()
  85. }
  86. }
  87. }
  88. stage('Package Legacy') {
  89. steps {
  90. dir('Build/Legacy/dist') {
  91. sh 'mkdir -p BepInEx/core BepInEx/patchers BepInEx/plugins'
  92. sh 'cp -fr -t BepInEx/core ../bin/*'
  93. sh 'rm -f BepInEx/core/UnityEngine.dll'
  94. sh 'rm -rf BepInEx/core/patcher'
  95. sh 'cp -f ../../../BepInEx/doorstop/doorstop_config.ini doorstop_config.ini'
  96. sh 'cp -f ../../../Doorstop/x86/winhttp.dll winhttp.dll'
  97. writeFile encoding: 'UTF-8', file: 'changelog.txt', text: changelog
  98. sh "zip -r9 BepInEx_Legacy_x86_${shortCommit}_${versionNumber}.zip ./*"
  99. sh 'cp -f ../../../Doorstop/x64/winhttp.dll winhttp.dll'
  100. sh 'unix2dos doorstop_config.ini changelog.txt'
  101. sh "zip -r9 BepInEx_Legacy_x64_${shortCommit}_${versionNumber}.zip ./* -x \\*.zip"
  102. archiveArtifacts "*.zip"
  103. }
  104. dir('Build/Legacy/patcher') {
  105. sh 'cp -fr ../bin/patcher/* .'
  106. writeFile encoding: 'UTF-8', file: 'changelog.txt', text: changelog
  107. sh 'unix2dos changelog.txt'
  108. sh "zip -r9 BepInEx_Legacy_Patcher_${shortCommit}_${versionNumber}.zip ./*"
  109. archiveArtifacts "*.zip"
  110. }
  111. }
  112. }
  113. stage('Package v2018') {
  114. steps {
  115. dir('Build/v2018/dist') {
  116. sh 'mkdir -p BepInEx/core BepInEx/patchers BepInEx/plugins'
  117. sh 'cp -fr -t BepInEx/core ../bin/*'
  118. sh 'rm -rf BepInEx/core/patcher'
  119. sh 'rm -f BepInEx/core/UnityEngine.dll'
  120. sh 'rm -f BepInEx/core/UnityEngine.CoreModule.dll'
  121. sh 'cp -f ../../../BepInEx/doorstop/doorstop_config.ini doorstop_config.ini'
  122. sh 'cp -f ../../../Doorstop/x86/winhttp.dll winhttp.dll'
  123. writeFile encoding: 'UTF-8', file: 'changelog.txt', text: changelog
  124. sh "zip -r9 BepInEx_v2018_x86_${shortCommit}_${versionNumber}.zip ./*"
  125. sh 'cp -f ../../../Doorstop/x64/winhttp.dll winhttp.dll'
  126. sh 'unix2dos doorstop_config.ini changelog.txt'
  127. sh "zip -r9 BepInEx_v2018_x64_${shortCommit}_${versionNumber}.zip ./* -x \\*.zip"
  128. archiveArtifacts "*.zip"
  129. }
  130. dir('Build/v2018/patcher') {
  131. sh 'cp -fr ../bin/patcher/* .'
  132. writeFile encoding: 'UTF-8', file: 'changelog.txt', text: changelog
  133. sh 'unix2dos changelog.txt'
  134. sh "zip -r9 BepInEx_v2018_Patcher_${shortCommit}_${versionNumber}.zip ./*"
  135. archiveArtifacts "*.zip"
  136. }
  137. }
  138. }
  139. }
  140. post {
  141. success {
  142. // Write built BepInEx into bepisbuilds
  143. dir('Build/Legacy/dist') {
  144. sh "cp BepInEx_Legacy_x86_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  145. sh "cp BepInEx_Legacy_x64_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  146. }
  147. dir('Build/Legacy/patcher') {
  148. sh "cp BepInEx_Legacy_Patcher_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  149. }
  150. dir('Build/v2018/dist') {
  151. sh "cp BepInEx_v2018_x86_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  152. sh "cp BepInEx_v2018_x64_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  153. }
  154. dir('Build/v2018/patcher') {
  155. sh "cp BepInEx_v2018_Patcher_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  156. }
  157. 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"
  158. //Notify Bepin Discord of successfull build
  159. withCredentials([string(credentialsId: 'discord-notify-webhook', variable: 'DISCORD_WEBHOOK')]) {
  160. 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
  161. }
  162. }
  163. failure {
  164. //Notify Discord of failed build
  165. withCredentials([string(credentialsId: 'discord-notify-webhook', variable: 'DISCORD_WEBHOOK')]) {
  166. 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
  167. }
  168. }
  169. }
  170. }