jenkins_master.groovy 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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('Build BepInEx') {
  42. steps {
  43. //TODO: Add builds for other Unity versions as well
  44. sh 'cp -f Unity/5.6/UnityEngine.dll BepInEx/lib/UnityEngine.dll'
  45. dir('BepInEx') {
  46. sh 'nuget restore'
  47. }
  48. dir('BepInEx/BepInEx') {
  49. // Write additional BuildInfo into the Bleeding Edge BepInEx.dll
  50. dir('Properties') {
  51. sh "echo '[assembly: BuildInfo(\"BLEEDING EDGE Build #${env.BUILD_NUMBER} from ${shortCommit} at ${branchName}\")]' >> AssemblyInfo.cs"
  52. sh "sed -i -E \"s/([0-9]+\\.[0-9]+\\.[0-9]+\\.)[0-9]+/\\1${env.BUILD_NUMBER}/\" AssemblyInfo.cs"
  53. script {
  54. versionNumber = sh(returnStdout: true, script: "grep -m 1 -oE \"[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\" AssemblyInfo.cs").trim()
  55. }
  56. }
  57. }
  58. // TODO: Build stuff selectively?
  59. dir('BepInEx') {
  60. sh 'msbuild /p:Configuration=Legacy /t:Build /p:DebugType=none BepInEx.sln'
  61. }
  62. }
  63. }
  64. stage('Package everything') {
  65. steps {
  66. dir('Build') {
  67. deleteDir()
  68. }
  69. dir('BepInEx/bin/patcher') {
  70. // NOTE: Currently we exclude patcher because we don't need it!
  71. deleteDir()
  72. }
  73. dir('Build') {
  74. sh 'mkdir -p BepInEx/core BepInEx/patchers'
  75. sh 'cp -f -t BepInEx/core ../BepInEx/bin/*'
  76. sh 'rm -f BepInEx/core/UnityEngine.dll'
  77. sh 'cp -f ../BepInEx/doorstop/doorstop_config.ini doorstop_config.ini'
  78. sh 'cp -f ../Doorstop/x86/winhttp.dll winhttp.dll'
  79. writeFile encoding: 'UTF-8', file: 'changelog.txt', text: changelog
  80. sh "zip -r9 BepInEx_x86_${shortCommit}_${versionNumber}.zip ./*"
  81. sh 'cp -f ../Doorstop/x64/winhttp.dll winhttp.dll'
  82. sh 'unix2dos doorstop_config.ini changelog.txt'
  83. sh "zip -r9 BepInEx_x64_${shortCommit}_${versionNumber}.zip ./* -x \\*.zip"
  84. }
  85. }
  86. }
  87. stage('Saving artifacts') {
  88. steps {
  89. archiveArtifacts 'Build/*.zip'
  90. }
  91. }
  92. }
  93. post {
  94. success {
  95. // Write built BepInEx into bepisbuilds
  96. dir('Build') {
  97. sh "cp BepInEx_x86_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  98. sh "cp BepInEx_x64_${shortCommit}_${versionNumber}.zip /var/www/bepisbuilds/builds/bepinex_be"
  99. 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"
  100. }
  101. // Notify Bepin Discord of successfull build
  102. withCredentials([string(credentialsId: 'discord-notify-webhook', variable: 'DISCORD_WEBHOOK')]) {
  103. 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
  104. }
  105. }
  106. failure {
  107. // Notify Discord of failed build
  108. withCredentials([string(credentialsId: 'discord-notify-webhook', variable: 'DISCORD_WEBHOOK')]) {
  109. 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
  110. }
  111. }
  112. }
  113. }