Jenkinsfile 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. pipeline {
  2. agent { label 'windows-host' }
  3. environment {
  4. DOTNET_CLI_TELEMETRY_OPTOUT = '1'
  5. JAVA_TOOL_OPTIONS = '-Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8'
  6. }
  7. stages {
  8. stage('Clean') {
  9. steps {
  10. bat 'if exist publish rmdir /s /q publish'
  11. }
  12. }
  13. stage('Build') {
  14. steps {
  15. bat 'chcp 65001 && dotnet publish Web.Api/Web.Api.csproj -c Release -o publish\\api'
  16. bat 'chcp 65001 && dotnet publish Admin/Admin.csproj -c Release -o publish\\admin'
  17. }
  18. }
  19. stage('Stop Services') {
  20. steps {
  21. bat 'chcp 65001 && sc.exe stop bitforum-Api || exit 0'
  22. bat 'chcp 65001 && sc.exe stop bitforum-Admin || exit 0'
  23. bat 'taskkill /F /IM Web.Api.exe 2>nul || exit 0'
  24. bat 'taskkill /F /IM Admin.exe 2>nul || exit 0'
  25. bat 'ping 127.0.0.1 -n 6 > nul'
  26. }
  27. }
  28. stage('Deploy API') {
  29. steps {
  30. bat 'chcp 65001 && robocopy publish\\api H:\\IIS\\bitforum-api\\sources /MIR /XF web.config restart.ps1 appsettings.Production.json /XD logs /NFL /NDL /NP & if %ERRORLEVEL% LEQ 7 exit /b 0'
  31. }
  32. }
  33. stage('Deploy Admin') {
  34. steps {
  35. bat 'chcp 65001 && robocopy publish\\admin H:\\IIS\\bitforum-admin\\sources /MIR /XF web.config restart.ps1 appsettings.Production.json /XD logs /NFL /NDL /NP & if %ERRORLEVEL% LEQ 7 exit /b 0'
  36. }
  37. }
  38. stage('Start Services') {
  39. steps {
  40. bat 'chcp 65001 && sc.exe start bitforum-Api'
  41. bat 'chcp 65001 && sc.exe start bitforum-Admin'
  42. }
  43. }
  44. }
  45. post {
  46. success { echo 'Backend deploy success!' }
  47. failure { echo 'Backend deploy failed!' }
  48. }
  49. }