jenkins_master.groovy 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. // Clean up old project before starting
  14. cleanWs()
  15. dir('BepInEx') {
  16. git 'https://github.com/BepInEx/BepInEx.git'
  17. script {
  18. shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
  19. longCommit = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
  20. branchName = sh(returnStdout: true, script: "git rev-parse --abbrev-ref HEAD").trim()
  21. latestTag = sh(returnStdout: true, script: "git describe --tags `git rev-list --tags --max-count=1`").trim()
  22. if(!params.IS_BE) {
  23. latestTagOnCurrentBranch = sh(returnStdout: true, script: "git describe --abbrev=0 --tags").trim()
  24. sh("git checkout ${latestTagOnCurrentBranch}")
  25. }
  26. if(params.IS_BE)
  27. changelog = gitChangelog from: [type: 'REF', value: "${latestTag}"], returnType: 'STRING', template: """BepInEx Bleeding Edge Changelog
  28. Changes since ${latestTag}:
  29. {{#commits}}
  30. {{^merge}}
  31. * [{{hash}}] ({{authorName}}) {{messageTitle}}
  32. {{/merge}}
  33. {{/commits}}""", to: [type: 'COMMIT', value: "${longCommit}"]
  34. }
  35. sh 'git submodule update --init --recursive'
  36. }
  37. dir('Unity') {
  38. withCredentials([string(credentialsId: 'bepis_dll_git_url', variable: 'bepis_dll_git_url')]) {
  39. git credentialsId: 'b1f2f78b-f0c5-4a81-8b4a-55b6b8bdbbe3', url: "${bepis_dll_git_url}/JenkinsStuff/UnityDLL.git"
  40. }
  41. }
  42. dir('Doorstop') {
  43. sh ''' tag="v2.11.1.0";
  44. version="2.11.1.0";
  45. wget https://github.com/NeighTools/UnityDoorstop/releases/download/$tag/Doorstop_x64_$version.zip;
  46. wget https://github.com/NeighTools/UnityDoorstop/releases/download/$tag/Doorstop_x86_$version.zip;
  47. unzip -o Doorstop_x86_$version.zip winhttp.dll -d x86;
  48. unzip -o Doorstop_x64_$version.zip winhttp.dll -d x64;'''
  49. }
  50. }
  51. }
  52. stage('Prepare BepInEx') {
  53. steps {
  54. dir('BepInEx') {
  55. sh "mkdir -p lib"
  56. // Ghetto fix to force TargetFrameworks to only net35
  57. sh "find . -type f -name \"*.csproj\" -exec sed -i -E \"s/(<TargetFrameworks>)[^<]+(<\\/TargetFrameworks>)/\\1net35\\2/g\" {} +"
  58. sh "nuget restore"
  59. }
  60. dir('BepInEx/BepInEx') {
  61. // Write additional BuildInfo into the Bleeding Edge BepInEx.dll
  62. dir('Properties') {
  63. script {
  64. if(params.IS_BE) {
  65. sh "sed -i -E \"s/([0-9]+\\.[0-9]+\\.[0-9]+\\.)[0-9]+/\\1${env.BUILD_NUMBER}/\" AssemblyInfo.cs"
  66. sh "echo '[assembly: BuildInfo(\"BLEEDING EDGE Build #${env.BUILD_NUMBER} from ${shortCommit} at ${branchName}\")]' >> AssemblyInfo.cs"
  67. }
  68. versionNumber = sh(returnStdout: true, script: "grep -m 1 -oE \"[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\" AssemblyInfo.cs").trim()
  69. }
  70. }
  71. }
  72. }
  73. }
  74. stage('Build BepInEx') {
  75. steps {
  76. sh 'cp -f Unity/5.6/UnityEngine.dll BepInEx/lib/UnityEngine.dll'
  77. dir('BepInEx') {
  78. sh 'msbuild /p:Configuration=Release /t:Build /p:DebugType=none BepInEx.sln'
  79. }
  80. dir('Build/bin') {
  81. sh 'cp -fr ../../BepInEx/bin/* .'
  82. }
  83. dir('BepInEx/bin') {
  84. deleteDir()
  85. }
  86. }
  87. }
  88. stage('Package') {
  89. steps {
  90. dir('Build/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. script {
  98. if(params.IS_BE) {
  99. writeFile encoding: 'UTF-8', file: 'changelog.txt', text: changelog
  100. sh 'unix2dos changelog.txt'
  101. commitPrefix = "_${shortCommit}_"
  102. }
  103. else
  104. commitPrefix = "_"
  105. }
  106. sh "zip -r9 BepInEx_x86${commitPrefix}${versionNumber}.zip ./*"
  107. sh 'cp -f ../../Doorstop/x64/winhttp.dll winhttp.dll'
  108. sh 'unix2dos doorstop_config.ini'
  109. sh "zip -r9 BepInEx_x64${commitPrefix}${versionNumber}.zip ./* -x \\*.zip"
  110. archiveArtifacts "*.zip"
  111. }
  112. dir('Build/patcher') {
  113. sh 'cp -fr ../bin/patcher/* .'
  114. script {
  115. if(params.IS_BE) {
  116. writeFile encoding: 'UTF-8', file: 'changelog.txt', text: changelog
  117. sh 'unix2dos changelog.txt'
  118. }
  119. }
  120. sh "zip -r9 BepInEx_Patcher${commitPrefix}${versionNumber}.zip ./*"
  121. archiveArtifacts "*.zip"
  122. }
  123. }
  124. }
  125. }
  126. post {
  127. success {
  128. /*
  129. script {
  130. if(params.IS_BE) {
  131. // Write built BepInEx into bepisbuilds
  132. dir('Build/dist') {
  133. sh "cp BepInEx_x86_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  134. sh "cp BepInEx_x64_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  135. }
  136. dir('Build/v2018/patcher') {
  137. sh "cp BepInEx_v2018_Patcher_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  138. }
  139. sh "echo \"`date -Iseconds -u`;${env.BUILD_NUMBER};${shortCommit};BepInEx_x86_${shortCommit}_${versionNumber}.zip;BepInEx_x64_${shortCommit}_${versionNumber}.zip\" >> /var/www/bepisbuilds/builds/bepinex_be/artifacts_list"
  140. }
  141. }
  142. */
  143. //Notify Bepin Discord of successfull build
  144. withCredentials([string(credentialsId: 'discord-notify-webhook', variable: 'DISCORD_WEBHOOK')]) {
  145. 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
  146. }
  147. }
  148. failure {
  149. //Notify Discord of failed build
  150. withCredentials([string(credentialsId: 'discord-notify-webhook', variable: 'DISCORD_WEBHOOK')]) {
  151. 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
  152. }
  153. }
  154. }
  155. }