jenkins_master.groovy 11 KB

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