jenkins_master.groovy 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. git credentialsId: 'b1f2f78b-f0c5-4a81-8b4a-55b6b8bdbbe3', url: 'http://localhost:6000/JenkinsStuff/UnityDLL.git'
  39. }
  40. dir('Doorstop') {
  41. sh ''' tag="v2.11.0.0";
  42. version="2.11.0.0";
  43. wget https://github.com/NeighTools/UnityDoorstop/releases/download/$tag/Doorstop_x64_$version.zip;
  44. wget https://github.com/NeighTools/UnityDoorstop/releases/download/$tag/Doorstop_x86_$version.zip;
  45. unzip -o Doorstop_x86_$version.zip version.dll -d x86;
  46. unzip -o Doorstop_x64_$version.zip version.dll -d x64;'''
  47. }
  48. }
  49. }
  50. stage('Prepare BepInEx') {
  51. steps {
  52. dir('BepInEx') {
  53. sh "mkdir -p lib"
  54. // Ghetto fix to force TargetFrameworks to only net35
  55. sh "find . -type f -name \"*.csproj\" -exec sed -i -E \"s/(<TargetFrameworks>)[^<]+(<\\/TargetFrameworks>)/\\1net35\\2/g\" {} +"
  56. sh "nuget restore"
  57. }
  58. dir('BepInEx/BepInEx') {
  59. // Write additional BuildInfo into the Bleeding Edge BepInEx.dll
  60. dir('Properties') {
  61. script {
  62. if(params.IS_BE) {
  63. sh "sed -i -E \"s/([0-9]+\\.[0-9]+\\.[0-9]+\\.)[0-9]+/\\1${env.BUILD_NUMBER}/\" AssemblyInfo.cs"
  64. sh "echo '[assembly: BuildInfo(\"BLEEDING EDGE Build #${env.BUILD_NUMBER} from ${shortCommit} at ${branchName}\")]' >> AssemblyInfo.cs"
  65. }
  66. versionNumber = sh(returnStdout: true, script: "grep -m 1 -oE \"[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\" AssemblyInfo.cs").trim()
  67. }
  68. }
  69. }
  70. }
  71. }
  72. stage('Build BepInEx') {
  73. steps {
  74. sh 'cp -f Unity/5.6/UnityEngine.dll BepInEx/lib/UnityEngine.dll'
  75. dir('BepInEx') {
  76. sh 'msbuild /p:Configuration=Release /t:Build /p:DebugType=none BepInEx.sln'
  77. }
  78. dir('Build/bin') {
  79. sh 'cp -fr ../../BepInEx/bin/* .'
  80. }
  81. dir('BepInEx/bin') {
  82. deleteDir()
  83. }
  84. }
  85. }
  86. stage('Package') {
  87. steps {
  88. dir('Build/dist') {
  89. sh 'mkdir -p BepInEx/core BepInEx/patchers BepInEx/plugins'
  90. sh 'cp -fr -t BepInEx/core ../bin/*'
  91. sh 'rm -f BepInEx/core/UnityEngine.dll'
  92. sh 'rm -rf BepInEx/core/patcher'
  93. sh 'cp -f ../../BepInEx/doorstop/doorstop_config.ini doorstop_config.ini'
  94. sh 'cp -f ../../Doorstop/x86/version.dll version.dll'
  95. script {
  96. if(params.IS_BE) {
  97. writeFile encoding: 'UTF-8', file: 'changelog.txt', text: changelog
  98. sh 'unix2dos changelog.txt'
  99. commitPrefix = "_${shortCommit}_"
  100. }
  101. else
  102. commitPrefix = "_"
  103. }
  104. sh "zip -r9 BepInEx_x86${commitPrefix}${versionNumber}.zip ./*"
  105. sh 'cp -f ../../Doorstop/x64/version.dll version.dll'
  106. sh 'unix2dos doorstop_config.ini'
  107. sh "zip -r9 BepInEx_x64${commitPrefix}${versionNumber}.zip ./* -x \\*.zip"
  108. archiveArtifacts "*.zip"
  109. }
  110. dir('Build/patcher') {
  111. sh 'cp -fr ../bin/patcher/* .'
  112. script {
  113. if(params.IS_BE) {
  114. writeFile encoding: 'UTF-8', file: 'changelog.txt', text: changelog
  115. sh 'unix2dos changelog.txt'
  116. }
  117. }
  118. sh "zip -r9 BepInEx_Patcher${commitPrefix}${versionNumber}.zip ./*"
  119. archiveArtifacts "*.zip"
  120. }
  121. }
  122. }
  123. }
  124. post {
  125. success {
  126. script {
  127. if(params.IS_BE) {
  128. // Write built BepInEx into bepisbuilds
  129. dir('Build/dist') {
  130. sh "cp BepInEx_x86_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  131. sh "cp BepInEx_x64_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  132. }
  133. /*
  134. dir('Build/v2018/patcher') {
  135. sh "cp BepInEx_v2018_Patcher_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  136. }
  137. */
  138. 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"
  139. }
  140. }
  141. //Notify Bepin Discord of successfull build
  142. withCredentials([string(credentialsId: 'discord-notify-webhook', variable: 'DISCORD_WEBHOOK')]) {
  143. 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
  144. }
  145. }
  146. failure {
  147. //Notify Discord of failed build
  148. withCredentials([string(credentialsId: 'discord-notify-webhook', variable: 'DISCORD_WEBHOOK')]) {
  149. 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
  150. }
  151. }
  152. }
  153. }