jenkins_master.groovy 10 KB

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