jenkins_master.groovy 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. script {
  14. if(fileExists('./last_build_commit'))
  15. lastBuildCommit = readFile 'last_build_commit'
  16. else
  17. lastBuildCommit = ""
  18. }
  19. // Clean up old project before starting
  20. cleanWs()
  21. dir('BepInEx') {
  22. git 'https://github.com/BepInEx/BepInEx.git'
  23. script {
  24. shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
  25. longCommit = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
  26. branchName = sh(returnStdout: true, script: "git rev-parse --abbrev-ref HEAD").trim()
  27. latestTag = sh(returnStdout: true, script: "git describe --tags `git rev-list --tags --max-count=1`").trim()
  28. if(!params.IS_BE) {
  29. latestTagOnCurrentBranch = sh(returnStdout: true, script: "git describe --abbrev=0 --tags").trim()
  30. sh("git checkout ${latestTagOnCurrentBranch}")
  31. }
  32. if(params.IS_BE)
  33. changelog = gitChangelog from: [type: 'REF', value: "${latestTag}"], returnType: 'STRING', template: """BepInEx Bleeding Edge Changelog
  34. Changes since ${latestTag}:
  35. {{#commits}}
  36. {{^merge}}
  37. * [{{hash}}] ({{authorName}}) {{messageTitle}}
  38. {{/merge}}
  39. {{/commits}}""", to: [type: 'COMMIT', value: "${longCommit}"]
  40. if(lastBuildCommit != "") {
  41. htmlChangelog = gitChangelog from: [type: 'COMMIT', value: lastBuildCommit], returnType: 'STRING',
  42. template: """<ul>{{#commits}}{{^merge}}<li>[<code>{{hash}}</code>] ({{authorName}}) {{messageTitle}}</li>{{/merge}}{{/commits}}</ul>""", to: [type: 'COMMIT', value: "${longCommit}"] }
  43. else
  44. htmlChangelog = ""
  45. }
  46. sh 'git submodule update --init --recursive'
  47. }
  48. dir('Unity') {
  49. withCredentials([string(credentialsId: 'bepis_dll_git_url', variable: 'bepis_dll_git_url')]) {
  50. git credentialsId: 'b1f2f78b-f0c5-4a81-8b4a-55b6b8bdbbe3', url: "${bepis_dll_git_url}/JenkinsStuff/UnityDLL.git"
  51. }
  52. }
  53. dir('Doorstop') {
  54. sh ''' tag="v2.11.1.0";
  55. version="2.11.1.0";
  56. wget https://github.com/NeighTools/UnityDoorstop/releases/download/$tag/Doorstop_x64_$version.zip;
  57. wget https://github.com/NeighTools/UnityDoorstop/releases/download/$tag/Doorstop_x86_$version.zip;
  58. unzip -o Doorstop_x86_$version.zip winhttp.dll -d x86;
  59. unzip -o Doorstop_x64_$version.zip winhttp.dll -d x64;'''
  60. }
  61. }
  62. }
  63. stage('Prepare BepInEx') {
  64. steps {
  65. dir('BepInEx') {
  66. sh "mkdir -p lib"
  67. // Ghetto fix to force TargetFrameworks to only net35
  68. sh "find . -type f -name \"*.csproj\" -exec sed -i -E \"s/(<TargetFrameworks>)[^<]+(<\\/TargetFrameworks>)/\\1net35\\2/g\" {} +"
  69. sh "nuget restore"
  70. }
  71. dir('BepInEx/BepInEx') {
  72. // Write additional BuildInfo into the Bleeding Edge BepInEx.dll
  73. dir('Properties') {
  74. script {
  75. if(params.IS_BE) {
  76. sh "sed -i -E \"s/([0-9]+\\.[0-9]+\\.[0-9]+\\.)[0-9]+/\\1${env.BUILD_NUMBER}/\" AssemblyInfo.cs"
  77. sh "echo '[assembly: BuildInfo(\"BLEEDING EDGE Build #${env.BUILD_NUMBER} from ${shortCommit} at ${branchName}\")]' >> AssemblyInfo.cs"
  78. }
  79. versionNumber = sh(returnStdout: true, script: "grep -m 1 -oE \"[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\" AssemblyInfo.cs").trim()
  80. }
  81. }
  82. }
  83. }
  84. }
  85. stage('Build BepInEx') {
  86. steps {
  87. sh 'cp -f Unity/5.6/UnityEngine.dll BepInEx/lib/UnityEngine.dll'
  88. dir('BepInEx') {
  89. sh 'msbuild /p:Configuration=Release /t:Build /p:DebugType=none BepInEx.sln'
  90. }
  91. dir('Build/bin') {
  92. sh 'cp -fr ../../BepInEx/bin/* .'
  93. }
  94. dir('BepInEx/bin') {
  95. deleteDir()
  96. }
  97. }
  98. }
  99. stage('Package') {
  100. steps {
  101. dir('Build/dist') {
  102. sh 'mkdir -p BepInEx/core BepInEx/patchers BepInEx/plugins'
  103. sh 'cp -fr -t BepInEx/core ../bin/*'
  104. sh 'rm -f BepInEx/core/UnityEngine.dll'
  105. sh 'rm -rf BepInEx/core/patcher'
  106. sh 'cp -f ../../BepInEx/doorstop/doorstop_config.ini doorstop_config.ini'
  107. sh 'cp -f ../../Doorstop/x86/winhttp.dll winhttp.dll'
  108. script {
  109. if(params.IS_BE) {
  110. writeFile encoding: 'UTF-8', file: 'changelog.txt', text: changelog
  111. sh 'unix2dos changelog.txt'
  112. commitPrefix = "_${shortCommit}_"
  113. }
  114. else
  115. commitPrefix = "_"
  116. }
  117. sh "zip -r9 BepInEx_x86${commitPrefix}${versionNumber}.zip ./*"
  118. sh 'cp -f ../../Doorstop/x64/winhttp.dll winhttp.dll'
  119. sh 'unix2dos doorstop_config.ini'
  120. sh "zip -r9 BepInEx_x64${commitPrefix}${versionNumber}.zip ./* -x \\*.zip"
  121. archiveArtifacts "*.zip"
  122. }
  123. dir('Build/patcher') {
  124. sh 'cp -fr ../bin/patcher/* .'
  125. script {
  126. if(params.IS_BE) {
  127. writeFile encoding: 'UTF-8', file: 'changelog.txt', text: changelog
  128. sh 'unix2dos changelog.txt'
  129. }
  130. }
  131. sh "zip -r9 BepInEx_Patcher${commitPrefix}${versionNumber}.zip ./*"
  132. archiveArtifacts "*.zip"
  133. }
  134. dir('Artifacts') {
  135. sh 'mv ../Build/patcher/*.zip .'
  136. sh 'mv ../Build/dist/*.zip .'
  137. }
  138. }
  139. }
  140. }
  141. post {
  142. cleanup {
  143. script {
  144. writeFile file: 'last_build_commit', text: lastBuildCommit
  145. }
  146. }
  147. success {
  148. script {
  149. lastBuildCommit = longCommit
  150. if(params.IS_BE) {
  151. dir('Artifacts') {
  152. def data = [
  153. id: env.BUILD_NUMBER,
  154. date: sh(returnStdout: true, script: 'date -Iseconds -u'),
  155. changelog: htmlChangelog,
  156. artifacts: [
  157. [
  158. file: "BepInEx_x64${commitPrefix}${versionNumber}.zip",
  159. description: "BepInEx for x64 machines"
  160. ],
  161. [
  162. file: "BepInEx_x86${commitPrefix}${versionNumber}.zip",
  163. description: "BepInEx for x86 machines"
  164. ],
  165. [
  166. file: "BepInEx_Patcher${commitPrefix}${versionNumber}.zip",
  167. description: "Hardpatcher for BepInEx. IMPORTANT: USE ONLY IF DOORSTOP DOES NOT WORK FOR SOME REASON!"
  168. ]
  169. ]
  170. ]
  171. def json = groovy.json.JsonOutput.toJson(data)
  172. json = groovy.json.JsonOutput.prettyPrint(json)
  173. writeFile file: 'info.json', text: json
  174. def filesToSend = findFiles(glob: '*').collect {it.name}
  175. withCredentials([string(credentialsId: 'bepisbuilds_addr', variable: 'BEPISBUILDS_ADDR')]) {
  176. sh """curl --upload-file "{${filesToSend.join(',')}}" --ftp-pasv --ftp-skip-pasv-ip --ftp-create-dirs --ftp-method singlecwd --disable-epsv ftp://${BEPISBUILDS_ADDR}/bepinex_be/artifacts/${env.BUILD_NUMBER}/"""
  177. }
  178. }
  179. }
  180. }
  181. //Notify Bepin Discord of successfull build
  182. withCredentials([string(credentialsId: 'discord-notify-webhook', variable: 'DISCORD_WEBHOOK')]) {
  183. discordSend description: "**Build:** [${currentBuild.id}](${env.BUILD_URL})\n**Status:** [${currentBuild.currentResult}](${env.BUILD_URL})\n\n[**Artifacts on BepisBuilds**](https://builds.bepis.io/projects/bepinex_be)", footer: 'Jenkins via Discord Notifier', link: env.BUILD_URL, successful: currentBuild.resultIsBetterOrEqualTo('SUCCESS'), title: "${env.JOB_NAME} #${currentBuild.id}", webhookURL: DISCORD_WEBHOOK
  184. }
  185. }
  186. failure {
  187. //Notify Discord of failed build
  188. withCredentials([string(credentialsId: 'discord-notify-webhook', variable: 'DISCORD_WEBHOOK')]) {
  189. 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
  190. }
  191. }
  192. }
  193. }