jenkins_master.groovy 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. }
  105. }
  106. stage('Package v2018') {
  107. steps {
  108. dir('Build/v2018/dist') {
  109. sh 'mkdir -p BepInEx/core BepInEx/patchers BepInEx/plugins'
  110. sh 'cp -fr -t BepInEx/core ../bin/*'
  111. sh 'rm -rf BepInEx/core/patcher'
  112. sh 'rm -f BepInEx/core/UnityEngine.dll'
  113. sh 'rm -f BepInEx/core/UnityEngine.CoreModule.dll'
  114. sh 'cp -f ../../../BepInEx/doorstop/doorstop_config.ini doorstop_config.ini'
  115. sh 'cp -f ../../../Doorstop/x86/winhttp.dll winhttp.dll'
  116. writeFile encoding: 'UTF-8', file: 'changelog.txt', text: changelog
  117. sh "zip -r9 BepInEx_v2018_x86_${shortCommit}_${versionNumber}.zip ./*"
  118. sh 'cp -f ../../../Doorstop/x64/winhttp.dll winhttp.dll'
  119. sh 'unix2dos doorstop_config.ini changelog.txt'
  120. sh "zip -r9 BepInEx_v2018_x64_${shortCommit}_${versionNumber}.zip ./* -x \\*.zip"
  121. archiveArtifacts "*.zip"
  122. }
  123. }
  124. }
  125. }
  126. post {
  127. success {
  128. // Write built BepInEx into bepisbuilds
  129. dir('Build/Legacy/dist') {
  130. sh "cp BepInEx_Legacy_x86_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  131. sh "cp BepInEx_Legacy_x64_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  132. }
  133. dir('Build/v2018/dist') {
  134. sh "cp BepInEx_v2018_x86_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  135. sh "cp BepInEx_v2018_x64_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  136. }
  137. 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\" >> /var/www/bepisbuilds/builds/bepinex_be/artifacts_list"
  138. //Notify Bepin Discord of successfull build
  139. withCredentials([string(credentialsId: 'discord-notify-webhook', variable: 'DISCORD_WEBHOOK')]) {
  140. discordSend description: "**Build:** [${currentBuild.id}](${env.BUILD_URL})\n**Status:** [${currentBuild.currentResult}](${env.BUILD_URL})\n\n**Artifacts:**\n- [BepInEx_x86_${shortCommit}_${versionNumber}.zip](${env.BUILD_URL}artifact/Build/BepInEx_x86_${shortCommit}_${versionNumber}.zip)\n- [BepInEx_x64_${shortCommit}_${versionNumber}.zip](${env.BUILD_URL}artifact/Build/BepInEx_x64_${shortCommit}_${versionNumber}.zip)", footer: 'Jenkins via Discord Notifier', link: env.BUILD_URL, successful: currentBuild.resultIsBetterOrEqualTo('SUCCESS'), title: "${env.JOB_NAME} #${currentBuild.id}", webhookURL: DISCORD_WEBHOOK
  141. }
  142. }
  143. failure {
  144. //Notify Discord of failed build
  145. withCredentials([string(credentialsId: 'discord-notify-webhook', variable: 'DISCORD_WEBHOOK')]) {
  146. 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
  147. }
  148. }
  149. }
  150. }